When you handle XML documents in .NET, you often need to find data of a node in the document. To find a node, there are many ways, here I will summarize several common methods to everyone. First, we have to do it to put an XML document into an XMLDocument object. First quote a few namespaces: use system.xml; use system.xml.xsl; use system.xml.xpath; these namespace everyone knows it according to the name, I will not say more here. Then the code is loaded into the XML file, the method is as follows: String XmlFile = "c: /mr.xml"; // The XMLFile is the path to the XML file you want to load. XMLDocument mydoc = new xmldocument (); // Defines an XMLDocument object. MyDoc.Load (XMLFile); this, we have an XML document called MYDOC. We will now find some nodes in this document. Let's first look at the content of this XML file. XML Version = "1.0" encoding = "UTF-8"?> Tim name> ready hobby> www.aspcool.com homepage > Member> Sandy name> learning hobby> member> shally name> translating hobby> member > Christine name> Working hobby> member> members> We can now find Name as Tim with the following method: MyDoc.childNodes.Item (1) .Childnodes.Item (0) .firstchild.innertext This method requires our layer to find the data we need inward, if there is a lot of levels, it will be very hard, and it is easy to make mistakes. Fortunately .NET gives us another method Selectsinglenode and SelectNodes method to let us find the data you want. For example, we have to find users named "TIM", we can use the following method: mydoc.selectsinglenode ("//member[name='tim']").childnodes.Item(1).innertext where / / Represents the child node of any layer inside. This way we can find what you want very quickly. SelectSinglenode is a single node that select Node can find a lot of nodes.
Looking for a child node in XML, everyone knows how to do it, we now go to a special XML file --- xsl file to find a child node, what should this be implemented? Suppose I now have such XSL files: XML Version = "1.0" encoding = "gb2312"?> XSL: Template>
center> td> tr> table> xsl: template> < / XSL: Stylesheet> We have two variables in ASP.NET, we need to use these two variables when the TRANSFORM XML file is used. How should we do it? The way I take is to load the XSL file as XML Document. Before using, we find the node that needs to be modified, and modify it with our variables.