473,327 Members | 2,007 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,327 software developers and data experts.

XPathNavigator.Select with a document that has default namespace only

I have an xml document as follows:

<?xml version="1.0" encoding="utf-8" ?>
<entityConfiguration xmlns="http://schemas.infinityinfo.com/entityconfiguration"
version="1.0">
<entity name="account">
<attribute name="accountid" />
</entity>
</entityConfiguration>

I am trying to find all 'entity' elements to iterate and the following are
the snippets:

// in static constructor
XmlDocument doc = new XmlDocument();
_configExpr = doc.CreateNavigator().Compile("/entityConfiguration/entity");
XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
ns.AddNamespace("", SchemaNamespace);
_configExpr.SetContext(ns);

// then in a method (xvr is a XmlValidatingReader for the above xml)
XPathDocument xpath = new XPathDocument(xvr);
XPathNavigator nav = xpath.CreateNavigator();
XPathNodeIterator itr = nav.Select(_configExpr); // this returns zero nodes.

Basically, the node set returned by the expression is 0. However, if I do:

XPathNodeIterator itr = nav.SelectDescendants("entity", SchemaNamespace,
false);

Then, I will get the correct list of entity element nodes. I could also
move to entityConfiguration node and use SelectChildren("entity", SchemaNamespace)
with success.
Since Select is the only one that takes a compiled expression, I would like
to know why it's not working properly.

Thanks in advance.

Jiho Han
Senior Software Engineer
Infinity Info Systems
The Sales Technology Experts
Tel: 212.563.4400 x216
Fax: 212.760.0540
jh**@infinityinfo.com
www.infinityinfo.com
Aug 9 '06 #1
2 9012


Jiho Han wrote:
I have an xml document as follows:

<?xml version="1.0" encoding="utf-8" ?>
<entityConfiguration
xmlns="http://schemas.infinityinfo.com/entityconfiguration" version="1.0">
<entity name="account">
<attribute name="accountid" />
</entity>
</entityConfiguration>

I am trying to find all 'entity' elements to iterate and the following
are the snippets:

// in static constructor
XmlDocument doc = new XmlDocument();
_configExpr = doc.CreateNavigator().Compile("/entityConfiguration/entity");
_configExpr =
doc.CreateNavigator().Compile("/pf:entityConfiguration/pf:entity");
XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
ns.AddNamespace("", SchemaNamespace);
ns.AddNamespace("pf", SchemaNamespace);

With XPath 1.0 you always need a prefix bound to a namespace URI to
select elements in that namespace, even if elements in the XML document
are in a default namespace and have no prefix. You can choose the prefix
as you like when you use the XPath API, and no change to the input XML
is needed

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 10 '06 #2
Hello Martin,

That worked perfectly. Thank you.

Jiho
Jiho Han wrote:
>I have an xml document as follows:

<?xml version="1.0" encoding="utf-8" ?>
<entityConfiguration
xmlns="http://schemas.infinityinfo.com/entityconfiguration"
version="1.0">
<entity name="account">
<attribute name="accountid" />
</entity>
</entityConfiguration>
I am trying to find all 'entity' elements to iterate and the
following are the snippets:

// in static constructor
XmlDocument doc = new XmlDocument();
_configExpr =
doc.CreateNavigator().Compile("/entityConfiguration/entity");
_configExpr =
doc.CreateNavigator().Compile("/pf:entityConfiguration/pf:entity");
>XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
ns.AddNamespace("", SchemaNamespace);
ns.AddNamespace("pf", SchemaNamespace);

With XPath 1.0 you always need a prefix bound to a namespace URI to
select elements in that namespace, even if elements in the XML
document are in a default namespace and have no prefix. You can choose
the prefix as you like when you use the XPath API, and no change to
the input XML is needed

Aug 11 '06 #3

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

Similar topics

1
by: Obe | last post by:
PLEASE HELP! I'm writing a function to populate DropDownLists from and xml file. I am having a problem getting my XPathNavigator to select any nodes when I attach a schema to my xml document. ...
4
by: David | last post by:
I'm using an XPathNodeIterator to select an element in an XML document that contains text I am going to put in a label on an aspx page. I want to be able to include HTML tags in the text read...
7
by: David Thielen | last post by:
Hi; Is there a way from an XPathNavigator object to get an xpath string that will, when used in a Select(xpath) on the underlying base/root XPathNavigator return the same XPathNavigator? In...
4
by: Andy Fish | last post by:
Hi, I can't figure out for the life of me how to select nodes using a namespace in XpathNavigator. For example: XPathDocument doc = new XPathDocument("file.xml"); XPathNavigator nav =...
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
0
by: kelvin273 | last post by:
Hi all, i'm new in this community (and in .NET programming) and i've a problem with xpathnavigator. The idea is to have an xml document with attribute editable by windows form. I write this...
2
by: =?Utf-8?B?Tm9yZW1hYw==?= | last post by:
Hi. Using VS2005, .NET 2.0. I have an xml document that I want to go through and set the values on attributes of elements. The elements are complex types defined in my schema (xsd) files. ...
5
by: Gigs_ | last post by:
hi i have xml in this structue <?xml version="1.0" encoding="utf-8" ?> <obrazac sifra="N-08-V"> <!-- Stanje: u obradi Primjedbe: nema -->
5
by: Andy Chambers | last post by:
Hi, On both Opera and Firefox, getElementsByTagName doesn't find anything apart from <optionelements inside a select element. Why is this? Here's a page that demonstrates this behaviour. I'd...
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.