I’ve been taking XML drills through Inner Working’s online certification. New ways of handling XML data have made it easier than ever. However, there are some pitfalls when querying XML. Below is an example. If you want to get and “ID” attribute from a document element, here is what you might do:
//Correct: Referencing the “Document Element” variable
documentID = xmldoc.DocumentElement.Attributes["id"].InnerXml;
//Correct: Selecting the “Document” node”
documentID = xmldoc.SelectSingleNode(“document”).Attributes["id"].InnerXml;
//Wrong: Selecting the “Document” node”
documentID = xmldoc.DocumentElement.SelectSingleNode(“document”).Attributes["id"].InnerXml;
Below is the full source
System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream (“WindowsFormsApplication1.resources.XMLFile.xml”);
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
string ItemID = xmldoc.SelectSingleNode(“document”).Attributes["id"].InnerXml;
Stuart Zahn is a software developer, blogger, and passionate about personal development. I believe there is intrinsic purpose behind all my work. As a programmer, my purpose is to help your business by delivering better software. I just call it creative indulgence. I try to put personal development and character above career. So, if you want to discuss personal development, partnerships, or job opportunities, please feel free to send me a message anytime.
No related posts.