473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

using namespace in xpath for SelectSingleNode

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);
Nov 12 '05 #1
1 6163


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 XmlNode xmlnode =
xmldoc.DocumentElement.SelectSingleNode("SOAP-ENV:Envelope/SOAP-ENV:Body/m:submit/parameter2/");


xmldoc.DocumentElement.SelectSingleNode(xpathExpre ssion,
namespaceManager)

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
3
by: muscha | last post by:
Hi All, I have this weird problem. I have an xml document and tried to do an XPath query to it. If I use the SelectSingleNode method it throws an exception but it works with SelectNodes method....
2
by: Michal Januszczyk | last post by:
I have a very simple XML document. <SmtpGatewayRules xmlns="http://www.foo.com/schema.xsd"> <rules> <rule> </rule> </rules> </SmtpGatewayRules> When no xmlns is specified I can find rule...
3
by: Jonathan | last post by:
Hi, I use a XML-Doc with a Namespace like the following example: <HomedResources xmlns=http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp Version="3"> <HomedResource...
2
by: dc | last post by:
i have a xml file like this: <?xml version="1.0" encoding="utf-8"?> <validate xmlns="http://tempuri.org/fieldValidate.xsd"> <field name="Short Name" type="SN" length="10"> <requiredChar...
1
by: Angela | last post by:
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...
1
by: Nick | last post by:
I am working on a website for a client and one of their requirements was to have a mailing list. I decided to XSLT to transform "templates" to HTML so that editing was very easy and less time...
3
by: rrm | last post by:
Hi I am verifying a SLD implementation using xml, however I have som problem using xpath and default namespaces in vb.net Currently I have the following xml <?xml version="1.0"?>...
3
by: =?Utf-8?B?bmVlZDJzY3ViYQ==?= | last post by:
I have the following code snipet: .... _xmldocManifest.Load(strManifestAbsolutePath) Dim manifestNSManager As XmlNamespaceManager = New XmlNamespaceManager(_xmldocManifest.NameTable)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.