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