c# - XmlDocument.SelectSingleNode returns null for root node -


I have many XML files that do not have postfix .xml, but I want to now handle them in the C # program. But it seems that C # slang can also find the basics of these XML files

  var doc = new XmlDocument (); Doc.Load (path); // MG: Edit XmlNode root = doc.SelectSingleNode ("rootNodename") to load on comment basis;  

It seems that the root is zero, how should I face it?

Given that you have load / LoadXml Illusion has solved, I hope this issue is the name space; Do you have XML? Handling XML with names ... "Funny"; -P

For example:

  XmlDocument doc = new XmlDocument (); Doc.LoadXml (@ "& lt; test xmlns = 'myFunkyUri' value = 'ABC' / & gt;"); // wrong; Do not consider any namespace XmlElement root = (XmlElement) doc.SelectSingleNode ("test"); Console.rootline (root == empty? ("No root)": root. GetAttribute ("value")); // Right XmlNamespaceManager nsmgr = New XmlNamespaceManager (doc.NameTable); Nsmgr.AddNamespace ("x", "myFunkyUri"); // My FUNYUURY = Root = (XMLAllment) is my nickname for the doctor. Selection Crowding Node ("X: Test", NSMGR); Console.rootline (root == empty? ("No root)": root. GetAttribute ("value"));  

Note, even if your XML declares the XML nickname, you may still need to re-declare it for your namespace manager.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -