SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : XML Technologies :

Previous DiscussionNext Discussion
 Handling namespaces in xpath queries

I have an xml document that starts

    <?xml version="1.0" encoding="utf-8"?>
    <LOGICALMODEL xmlns="urn:bt-cssschema">
        <LOGICALNODE>
            <VarType>DP</VarType>

I want to read nodes from it using c#. If I create an xpath and read it like this:

     string xpathQuery = "/LOGICALMODEL/LOGICALNODE[VarType='DP']";
System.Xml.XmlNodeList list = m_xmlDoc.SelectNodes(xpathQuery);

The list is empty. If I edit the xml so that it doesn't have the xmlns part, then the list gets all the nodes I would expect it to. Can anyone please tell me how I can modify the code so that it gets the logical nodes when the xmlns attribute is present in the input file?

Thanks

Steve

Started By SteveClay on Jan 27, 2006 at 4:33:51 AM

3 Response(s) | Reply

Earlier Replies | Replies 2 to 3 of 3 | Later Replies
MHenke on Jan 27, 2006 at 5:23:57 AM (# 2)

Not in C# (OTTOMH).

But the behaviour is perfectly valid. All the nodes in your example belongs to the default namespace "urn:bt-cssschema", your XPath query requests nodes that are in no namespace.

It should be easy to look up, a common task for all XPath supporting XML processors...

... here we go (from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemxmlxmlnodeclassselectnodestopic1.asp):

Remarks

If the XPath expression requires namespace resolution, you must use the SelectNodes overload which takes an XmlNamespaceManager as its argument. The XmlNamespaceManager is used to resolve namespaces.

And here it is...


SteveClay on Jan 27, 2006 at 6:16:02 AM (# 3)

MHenke,

Thank you very much, perfect, works a treat!

Thanks


Earlier Replies | Replies 2 to 3 of 3 | Later Replies

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.