469,282 Members | 1,953 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Still having problems with NameSpaceManager

Hi,

I'm trying to extract data from objects that contain xml that fits a
third party schema with it's own root namespace. I've added a
namespace manager that seemed to work most of the time but I never
fully understood why. I've now hit another problem. It might be code
blindness but I can't see why it doesn't work.

I am trying to select a node using XPath from an XmlElement

XmlElement xEntityNode ;

/* xEntityNode's OuterXml is this
<facilityList xmlns="qvEntityTypes">
<facility>
<internalId>6</internalId>
<description>OrderOnLine</description>
<displayOrder>1</displayOrder>
</facility>
<facility>
<internalId>7</internalId>
<description>ConfirmHeldOrders</description>
<displayOrder>1</displayOrder>
</facility>
<facility>
<internalId>28</internalId>
<description>ViewProductStock</description>
<displayOrder>1</displayOrder>
</facility>
<facility>
<internalId>29</internalId>
<description>SeeOtherUsersOrders</description>
<displayOrder>1</displayOrder>
</facility>
<facility>
<internalId>30</internalId>
<description>Buy</description>
<displayOrder>1</displayOrder>
</facility>
</facilityList>
*/

// Here's my code
nsmgr = new XmlNamespaceManager( new System.Xml.NameTable() );
nsmgr.AddNamespace("qv", "qvEntityTypes") ;
XmlNode propertyNode = xEntityNode.SelectSingleNode(
"//qv:facilityList/qv:facility[description = \"Buy\"]" , nsmgr);

// END

SelectSingleNode returns null. I think the namespace applies to the
nested facility level hence the qv:facility.

Can anyone suggest a better way of dealing with the namespace?
Nov 12 '05 #1
2 2427
"Chris" <fr*******@surf.to> wrote in message news:57*************************@posting.google.co m...
It might be code blindness but I can't see why it doesn't work.
Definitely code blindness. ;-)

: : XmlNode propertyNode = xEntityNode.SelectSingleNode(
"//qv:facilityList/qv:facility[description = \"Buy\"]" , nsmgr);


The XPathExpression that successfully returns a node is,

//qv:facilityList/qv:facility[qv:description = 'Buy']

The prefix that you correctly used on each of the location
steps is also required on the child element, description, in
the expression's predicate.
Derek Harmon
Nov 12 '05 #2
Oh yeah. Should have tried that. Thanks :-)

"Derek Harmon" <lo*******@msn.com> wrote in message news:<#k*************@TK2MSFTNGP11.phx.gbl>...
"Chris" <fr*******@surf.to> wrote in message news:57*************************@posting.google.co m...
It might be code blindness but I can't see why it doesn't work.


Definitely code blindness. ;-)

: :
XmlNode propertyNode = xEntityNode.SelectSingleNode(
"//qv:facilityList/qv:facility[description = \"Buy\"]" , nsmgr);


The XPathExpression that successfully returns a node is,

//qv:facilityList/qv:facility[qv:description = 'Buy']

The prefix that you correctly used on each of the location
steps is also required on the child element, description, in
the expression's predicate.
Derek Harmon

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

687 posts views Thread by cody | last post: by
8 posts views Thread by Michael C | last post: by
4 posts views Thread by Charles | last post: by
reply views Thread by Wayne Wengert | last post: by
8 posts views Thread by Brad Simon | last post: by
14 posts views Thread by Alan Silver | last post: by
reply views Thread by Martin | last post: by
1 post views Thread by Bruce Sandeman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.