Through XPath, we can quickly find the desired node, such:
<?xml version=/"1.0/" encoding=/"ISO-8859-1/"?> <urlset><url><loc>http://blog.stevex.net/</loc></url></urlset>
Use the following code to search for the URL node xmlnodelist urlnodes = Doc. selectnodes ("/urlset/url ");
However, if you change the XML:
<?xml version=/"1.0/" encoding=/"ISO-8859-1/"?><urlset xmlns="http://www.google.com/schemas/sitemap/0.84"><url><loc>http://blog.stevex.net/</loc></url></urlset>
When xmlnodelist urlnodes = Doc. selectnodes ("/urlset/url") is used, an empty list is returned, that is, the URL node cannot be searched.
You can use xmlnamespacemanager to solve this problem:
XmlNamespaceManager nsMgr = new XmlNamespaceManager(myXmlDoc.NameTable); nsMgr.AddNamespace("sm", http://www.google.com/schemas/sitemap/0.84); XmlNode urlNodes = doc.SelectNodes("/sm:urlset/sm:url",nsMgr);
If multiple namespaces are added, you can use other namespaces to query nodes.