Tuesday, 20 February 2018

c# - XMLDocument GetElementByID returning null




I'm trying to get an element of a xml by using the function GetElementById, but the function is always returning null.



//get xml text from a web service
string xml = aS.createTree();
XmlDocument tree = new XmlDocument();
tree.LoadXml(xml);

//get all nodes with the tag name "item"
XmlNodeList node = tree.GetElementsByTagName("item");

//just for test to see if i could get the attribute value which returns the expected
string idTemp = node[0].Attributes["ID"].Value;
XmlElement elem = tree.GetElementById("1");


elem is always returning null. Can you guys help me out?



By the way this is the xml that i'm trying to parse:








]>



















Answer



As far as I know the id att cannot start with a number. Can you try some thing like id="_1" and see how it works.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...