473,386 Members | 1,785 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,386 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 17 '05 #1
1 3980


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 17 '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...
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...
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: 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"?>...
0
by: rnaimon | last post by:
I found the following information on this site, but I am unable to get it to work. All it brings back is the xml page with no data. I am running a Windows 2003 Server with Exchange 2003 Server. ...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.