all groups > dotnet xml > may 2005 >
You're in the

dotnet xml

group:

using namespace in xpath for SelectSingleNode


Re: using namespace in xpath for SelectSingleNode Martin Honnen
5/27/2005 12:00:00 AM
dotnet xml:


[quoted text, click to view]

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]

xmldoc.DocumentElement.SelectSingleNode(xpathExpression,
namespaceManager)

--

Martin Honnen --- MVP XML
using namespace in xpath for SelectSingleNode Angela
5/27/2005 10:28:32 AM
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?
Thanks.



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);



XmlNode xmlnode =
xmldoc.DocumentElement.SelectSingleNode("SOAP-ENV:Envelope/SOAP-ENV:Body/m:submit/parameter2/");

xmlnode.AppendChild(cdata);

AddThis Social Bookmark Button