Import XML file without stylesheet
-
Hi I need to populate a datatable with two fields from an xml file. and The file was obtained from a report that opens in a web browser, and the file saved from there.
DataTabel.ReadXml(XMLFilename)
fails (complains about the ':' character in Line 2 of the xml file.) I thought about using something like below, since I do have a complete list of the in another table, but the is not a child node of , and this also fails (complains about the ':' character in Line 2 of the xml file.)
public string GetKeyValue(string key)
{
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
xd.Load(_XMLFileName);
System.Xml.XmlNode Node = xd.DocumentElement.SelectSingleNode("/REPORTTABLE/REPORTTABLEDETAILS/PARTNUM add[@key=\"" + key + "\"]");if ((Node != null)) { return Node.Attributes.GetNamedItem("value").Value; } else { return null; } }
Any idea how I can get a list of PARTNUM with the corresponding ACTUALQTYNUM?
2014/07/11 13:36:44
Fujiuser
Week_23_2014260-C536000-PACE - Top_TLine 1 / Line 1 / Top / 1
260-C536000-PACE - Top_BLine 2 / VEK Line 2 / Bottom / 1
38
938-1030507938-1030507938-1030507
2
2
0
4
6249
6245948-1025627948-1025627948-1025627
2
1
-1
40
6720
6680 -
Hi I need to populate a datatable with two fields from an xml file. and The file was obtained from a report that opens in a web browser, and the file saved from there.
DataTabel.ReadXml(XMLFilename)
fails (complains about the ':' character in Line 2 of the xml file.) I thought about using something like below, since I do have a complete list of the in another table, but the is not a child node of , and this also fails (complains about the ':' character in Line 2 of the xml file.)
public string GetKeyValue(string key)
{
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
xd.Load(_XMLFileName);
System.Xml.XmlNode Node = xd.DocumentElement.SelectSingleNode("/REPORTTABLE/REPORTTABLEDETAILS/PARTNUM add[@key=\"" + key + "\"]");if ((Node != null)) { return Node.Attributes.GetNamedItem("value").Value; } else { return null; } }
Any idea how I can get a list of PARTNUM with the corresponding ACTUALQTYNUM?
2014/07/11 13:36:44
Fujiuser
Week_23_2014260-C536000-PACE - Top_TLine 1 / Line 1 / Top / 1
260-C536000-PACE - Top_BLine 2 / VEK Line 2 / Bottom / 1
38
938-1030507938-1030507938-1030507
2
2
0
4
6249
6245948-1025627948-1025627948-1025627
2
1
-1
40
6720
6680 -
Thanks for your reply Richard. From W3.org it seems the file is possibly not 100% compliant
xml:stylesheet
should be
xml-stylesheet
But even so, I eventually got hold of the stylesheet which did not have any Schema info. Also tried DataSet.ReadXml as many posts on the net suggested where a schema was not available with no luck. Ended up reading the file with StreamReader.ReadLine and picking out the values I needed with SubString(...)
-
Thanks for your reply Richard. From W3.org it seems the file is possibly not 100% compliant
xml:stylesheet
should be
xml-stylesheet
But even so, I eventually got hold of the stylesheet which did not have any Schema info. Also tried DataSet.ReadXml as many posts on the net suggested where a schema was not available with no luck. Ended up reading the file with StreamReader.ReadLine and picking out the values I needed with SubString(...)
Having to deal with defective XML files is always fun... My 5 for seeing that little difference. Alternatively to your solution, write the file back line by line, just omitting the "bad" line. With that file, some tools could generate classes for its content, and thus making the access to the properties easier. The Japanese encoding could cause some more fun later on, be prepared for that.