I have this XML (stored in a C # line called myXML )
<?xml version="1.0" encoding="utf-16"?> <myDataz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <listS> <sog> <field1>123</field1> <field2>a</field2> <field3>b</field3> </sog> <sog> <field1>456</field1> <field2>c</field2> <field3>d</field3> </sog> </listS> </myDataz>
and I would like to see all the <sog> elements. For each of them, I would like to print a child of <field1> .
So this is my code:
XmlDocument xmlDoc = new XmlDocument(); string myXML = "<?xml version=\"1.0\" encoding=\"utf-16\"?><myDataz xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><listS><sog><field1>123</field1><field2>a</field2><field3>b</field3></sog><sog><field1>456</field1><field2>c</field2><field3>d</field3></sog></listS></myDataz>" xmlDoc.Load(myXML); XmlNodeList parentNode = xmlDoc.GetElementsByTagName("listS"); foreach (XmlNode childrenNode in parentNode) { HttpContext.Current.Response.Write(childrenNode.SelectSingleNode("//field1").Value); }
but it seems I can not read the string as XML? I get a System.ArgumentException
markzzz Dec 06 2018-11-11T00: 00Z
source share