dotnet xml:
[quoted text, click to view] Angela wrote:
> I am getting an error when I attempt to access a node with
> SelectSingleNode(): "The expression passed to this method should result in a
> NodeSet." I understand there is some confusion when you have to state a
> namespace in the xpath. Can the node be accessible by the xpath specified?
> XmlDocument xmldoc = new XmlDocument();
>
> XmlCDataSection cdata = xmldoc.CreateCDataSection(requestString);
>
>
>
> String soapEnvelope =
>
> "<SOAP-ENV:Envelope
> xmlns:SOAP-ENV=\"
http://schemas.xmlsoap.org/soap/envelope/\"
>
> xmlns:xsi=\"
http://wwww3.org/1999/XMLSchema-instance\"
>
> xmlns:xsd\"
http://www.w3.org/1999/XMLSchema\">
>
> <SOAP-ENV:Body>
>
> <m:submit xmlns:m=\"com.abc.def\">
>
> <parameter1>TEST</parameter1>
>
> <parameter2></parameter2>
>
> </m:submit>
>
> </SOAP-ENV:Body>
>
> </SOAP-ENV:Envelope>";
>
> xmldoc.LoadXml(soapEnvelope);
>
You should create and use a namespace manager e.g.
XmlNamespaceManager namespaceManager = new
XmlNamespaceManager(xmldoc.NameTable);
then add the namespaces you need e.g.
namespaceManager.Add("SOAP-ENV",
"
http://schemas.xmlsoap.org/soap/envelope");
namespaceManager.Add("m", "com.abc.def");
then pass the namespace manager to the SelectSingleNode method
[quoted text, click to view] > XmlNode xmlnode =
> xmldoc.DocumentElement.SelectSingleNode("SOAP-ENV:Envelope/SOAP-ENV:Body/m:submit/parameter2/");
xmldoc.DocumentElement.SelectSingleNode(xpathExpression,
namespaceManager)
--
Martin Honnen --- MVP XML