I have an small issue of adding an XML nodelist to a datagrid. It is as follows:
I have a few code blocks that read in the nodelist from an XML file that I was able to find in several forums starting with this one which I have tweaked to suit. I am grabbing the proper nodelist (ServiceHistory) and all works well unti I try and add custom columns etc.
public static DataTable ConvertXmlNodeListToDataTable(XmlNodeList xnl)
DataTable dt = new DataTable();
string strOpCode, strDescription; //set up error code vars
int TempColumn = 0;
foreach (XmlNode node in xnl.Item(0).ChildNodes)
DataColumn dc = new DataColumn(node.Name, System.Type.GetType("System.String"));
if (node.Name == "Operation") //Need to get the OpCode and Descriptions out
CodesDesc(node.InnerText, out strOpCode, out strDescription);
The CodeDesc void is used to break strings out one of the nodes(<operation>) and into 2 new data columns. I am having trouble figuring out just how to go about adding the columns I want(the OpCode and Description columns) and get the strings from the Operations.Innertext into those.
public static void CodesDesc(string OpsText, out string strOpCode, out string strDescription)
int Lpos = OpsText.IndexOf("*");
int Rpos = OpsText.LastIndexOf("*") +1;
<?xmlversion="1.0"encoding="UTF-8"?><api:replyxmlns:api="http://www.site.com/api"version="1.0"><Session><Replytype="Connection"><ErrorMessage/><ErrorCode>0</ErrorCode></Reply><Replygroup="T1G1"object="ServiceHistory"type="Get"><ServiceHistory><RecordID>XF301274*9929</RecordID><SWR>661</SWR><Operation>BSRS*IBN****REPAIR RIGHT SIDE DAMAGE</Operation><PartsAmount>31.20</PartsAmount><LaborAmount>543.00</LaborAmount></ServiceHistory><ServiceHistory><RecordID>XF301274*9929</RecordID><SWR>661</SWR><Operation>RP*IBN****REFINISH & PAINT DAMAGED AREA</Operation><PartsAmount>0.00</PartsAmount><LaborAmount>351.00</LaborAmount></ServiceHistory><ServiceHistory><RecordID>XF301274*9929</RecordID><SWR>661</SWR><Operation>PM*IPM****PAINT & MATERIAL</Operation><PartsAmount>0.00</PartsAmount><LaborAmount>198.90</LaborAmount></ServiceHistory><ErrorMessage/><ErrorCode>0</ErrorCode></Reply></Session></api:reply>
I apologize. Let me try an explain further. I need to split the Operation Element innertext which is being done. The issue is trying to get that text into the datatable row properly. I have modified the function some to add columns as I know what those are going to be. It is the childnode values that change and I need to take Operation childnode and change the loop to add the OpCode and Description strings rather than the Operation childnode innertext.
publicstatic DataTable ConvertXmlNodeListToDataTable(XmlNodeList xnl)
DataTable dt = new DataTable();
string strOpCode, strDescription; //set code vars
int ColumnsCount = dt.Columns.Count;
for (int i = 0; i < xnl.Count; i++)
DataRow dr = dt.NewRow();
for (int j = 0; j < ColumnsCount; j++)
if (xnl.Item(i).ChildNodes[j].Name == "Operation")
CodesDesc(xnl.Item(i).ChildNodes[j].InnerText, out strOpCode, out strDescription);
dr[j] = strOpCode.ToString();
dr[j+1] = strDescription.ToString();
dr[j] = xnl.Item(i).ChildNodes[j].InnerText;
Does this help clear things up? I amnot able to insert the text into the datarow properly during the for loop which iswhere my headaches are coming from..
I would like to know how the HTML source of ajax based sites can be read using HttpWebRequest / HttpWebResponse (That is reading the contents of a website at server side). The problem that I'm facing is that I'm unable to read parts of the webpage which uses Ajax or stuffs like UpdatePanel.
I don't know of any implementations that can scrape this.
Can anyone help, I am getting an object reference error in my code. All I am doing is adding two tables to one table, the tables that are being added are Genealogy Table and Relationship Table to Details Table.
The error is below:
An object reference is required for the non-static field, method, or property 'MvcGenealogy.Models.GRHolding.GetDetailID(System.Web.HttpContextBase)'
The error is part of a holding model, the code that is causing the error is below:
publicstatic GRHolding GetDetail(HttpContextBase context)
var detail = new GRHolding();
detail.GRHoldingID = GRHolding.GetDetailID(context);
It references the GetDetailID, the code is below and come from the same Model.GRHolding:
publicstring GetDetailID(HttpContextBase context)
if (context.Session[DetailsSessionKey] == null)
context.Session[DetailsSessionKey] = context.User.Identity.Name;
// Generate a new random GUID using System.Guid class
Guid tempDetailsID = Guid.NewGuid();
// Send tempDetailsID back to client as a cookie
context.Session[DetailsSessionKey] = tempDetailsID.ToString();
I do have a Session in my Model call DetailsSessionKey which is a string and identifies with the DetailsID. The code that declares this is here:
I think the problem is in my session because the error is with this line of code "detail.GRHoldingID = GRHolding.GetDetailID(context);", which under the GetDetail in my GRHolding.cs model. It is not converting it to a string properly. I think it is something minor in the session, can anyone help? All I am to doing is associating two tables, (Genealogy table and Relationship table), with one table, (Details table).
Ehm, that's actually beginner's stuff, isn't it?
detail.GRHoldingID = detail.GetDetailID(context);
assigns the return value of the GRHoldingID function to the GRHoldingID property.
From the code snippet you showed us, we can see that GRHoldingID returns a string.
From the error message, we can conclude that the GRHoldingID property is an integer.
Since we do not have more information about that class and its business rules, we cannot provide a "correct" solution safely.
You might change the GRHoldingID property to a string, or you might try to get an integer value from the string, i.e.
string strID = detail.GetDetailID(context);
if (int.TryParse(strID, out id))
detail.GRHoldingID = id;
// how do you want to handle this error case?
Hi. I want to develop an application that recognizes the language. This app will listen to (capture sound from the microphone) the speech, and if it detects a specific language (Armenian), the application will show the message "The Armenian language is found." The app will work with only one language, and only discover it.
How realize it? How to teach this application to detect the language?
With the state of speech recognition as it stands right now, this is next to impossible. There are too many things that affect the quality of speech recognition that throwing in another uncertainty would not help. Suppose that I was to use the Geordie phrase (it's an English regional dialect) of "Why aaz a ganning hyem". What language would it identify? I still speak English, but in this case, it would determine that I'm speaking Danish which has a similar phrase.
Your best bet would be to start up approx. 250 processes - one for each language and pass the audio input to each one in parallel. After a set time, any that haven't recognised the language should shut down - eventually you will get to your required language.