Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function
You have to add xsl
namespace to XmlNamespaceManager
:
var document = new XmlDocument();document.Load(...);var nsmgr = new XmlNamespaceManager(document.NameTable);nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");var nl = document.SelectNodes("//xsl:import/@href", nsmgr);
The document can be traversed by GetElementsByTagName
and it doesn't necessarily need using XmlNamespaceManager
:
var nodes = document.GetElementsByTagName("xsl:import");var href = nodes[0].Attributes["href"];
var document = new XmlDocument();document.LoadXml(rawData);var nsmgr = new XmlNamespaceManager(document.NameTable);nsmgr.AddNamespace("cbc", "urn:xxx"); //for examplensmgr.AddNamespace("cac", "urn:yyy"); XmlElement xmlElem = document.DocumentElement;var node = xmlElem.SelectSingleNode("cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID[@schemeID='VKN']/text()", nsmgr);var nodeText = node.InnerText;
All namespaces that will be used in XML should be added.
Then you can access the values of the relevant nodes using xpath
.