{"id":309,"date":"2016-08-26T02:54:56","date_gmt":"2016-08-26T02:54:56","guid":{"rendered":"http:\/\/waynenguyen.org\/dev\/?p=309"},"modified":"2016-08-26T03:00:37","modified_gmt":"2016-08-26T03:00:37","slug":"selecting-nodes-with-no-namespace-using-xpath-in-c","status":"publish","type":"post","link":"https:\/\/bruceng.com\/dev\/?p=309","title":{"rendered":"Selecting nodes with no namespace using XPath in C#"},"content":{"rendered":"<p>When nodes in an XML document has no prefix at all you would think that they are associated with the default namespace, but apparently this is not the case.<\/p>\n<p>Those nodes are considered not associated with any namespace at all. So to select them using XPath, in the NamespaceManager first add\u00a0the default\u00a0namespace with any arbitrary prefix of your choosing <strong>but not string.Empty<\/strong>, for example:<\/p>\n<p>namespaceManager.AddNameSpace(&#8220;x&#8221;, &#8220;http:\/\/&#8230;&#8221;);<\/p>\n<p>Here x is just a randomly chosen prefix<\/p>\n<p>Then, you can use XPath to select nodes using the prefix you just added<\/p>\n<p>doc.SelectNodes(&#8220;\/\/x:NodeName&#8221;, namespaceManager);<\/p>\n<p>I spent 2 hours to figure this out, talk about wasting time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When nodes in an XML document has no prefix at all you would think that they are associated with the default namespace, but apparently this is not the case. Those nodes are considered not associated with any namespace at all. So to select them using XPath, in the NamespaceManager first add\u00a0the default\u00a0namespace with any arbitrary &hellip; <a href=\"https:\/\/bruceng.com\/dev\/?p=309\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Selecting nodes with no namespace using XPath in C#&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[7,43,44],"class_list":["post-309","post","type-post","status-publish","format-standard","hentry","category-problems","tag-c","tag-xml","tag-xpath"],"_links":{"self":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=309"}],"version-history":[{"count":2,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/309\/revisions"}],"predecessor-version":[{"id":311,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/309\/revisions\/311"}],"wp:attachment":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}