473,385 Members | 1,901 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,385 software developers and data experts.

"s:" in xpath causes error

Hi all,

I have the following simplified version of xml file:

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row'>
<s:AttributeType name='Fund1'>
<s:AttributeType name='Fund2'>
<s:AttributeType name='Fund3'>
</s:ElementType>
</s:Schema>
</xml>

In my C# code, I use xpath as follows:

XmlNodeList items = document.SelectNodes
("//s:Schema/s:ElementType/s:AttributeType");

This causes runtime error, "An unhandled exception of type
'System.Xml.XPath.XPathException' occurred in system.xml.dll"

Any advice on how to work-around the prefix of "s:" in the xpath? Many
thanks!

Apr 18 '06 #1
2 1888
Try using the overload taking an additional XmlNamespaceManager argument,
something like.

XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("s", "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'");

XmlNodeList items =
document.SelectNodes("//s:Schema/s:ElementType/s:AttributeType",nsmgr);
"Emily" <fi********@yahoo.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Hi all,

I have the following simplified version of xml file:

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row'>
<s:AttributeType name='Fund1'>
<s:AttributeType name='Fund2'>
<s:AttributeType name='Fund3'>
</s:ElementType>
</s:Schema>
</xml>

In my C# code, I use xpath as follows:

XmlNodeList items = document.SelectNodes
("//s:Schema/s:ElementType/s:AttributeType");

This causes runtime error, "An unhandled exception of type
'System.Xml.XPath.XPathException' occurred in system.xml.dll"

Any advice on how to work-around the prefix of "s:" in the xpath? Many
thanks!

Apr 18 '06 #2
Hi Clive,

Many thanks! Your suggestion works.

Apr 19 '06 #3

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

Similar topics

3
by: Philipp Lenssen | last post by:
I want to try the new Yahoo API, but I get the PHP5 error message Unknown encoding "utf-8" in the marked line below... (After that, applying the Xpath will fail as symptom of the first bug.) ...
0
by: jacksuyu | last post by:
I have two xsd files, in one xsd file, I defined a "key", I'd like to use "keyref" to refer to that "key" from another xsd file. But I always get attribute is empty error. my.xsd is my first xsd...
2
by: Jaunedeau | last post by:
I have some XML that must look like this : <movies> <movie id="1"> <actor preferredMovieId="1"> <actor preferredMovieId="2"> <actor preferredMovieId="3"> </movie> <movie id="2"> <actor...
2
by: Alistair Bayley | last post by:
(.Net framework version 1.1.4322) The following XSL test case is rejected by System.Xml.Xsl.XslTransform, with an XsltException: "($dummy)+0 is an invalid XPath expression." If you remove the...
2
by: John A Grandy | last post by:
Is there something special in XML about the name "Parameter" ... I am not able to XPATH query for nodes named "Parameter" <Root> <Category CategoryID="1"> <Elements> <Element...
0
by: jacqueharper | last post by:
I am having a problem with an Excel ListObject in my C# .NET application. I am trying to map an XML schema to a ListObject, and continue to get the error "The XPath is not valid because either the...
4
by: lisa | last post by:
I have an XML file that starts like this: <?xml version="1.0" encoding="ISO-8859-1" xmlns:fn="http://www.w3.org/2005/xpath-functions"?> <Authors> <Author> <ID>2</ID>...
1
by: alien_attack | last post by:
I have the a repeater which is databound to an XmlDatasource. Inside the repeater is a Label as follows: <asp:Label ID="lbl" runat="server" Text='<%# XPath("Asset_Metadata/@Value")%>' /> ...
1
by: niharnayak2003 | last post by:
Hi All, I am facing the problem in Typecast inside the Generic class. I need a function which will take two param 1:-Xpath 2:- XMLDOC and return me what i will need. here is the code for...
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: 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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.