471,610 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,610 software developers and data experts.

XPath question

Hi,
I have a question regarding XPath and namespaces. I have a piece of XML...

<Cred>
<Meta>
<Type xmlns='syncml:metinf'>syncml:auth-basic</Type>
</Meta>
<Data>QnJ1Y2UyOk9oQmVoYXZl</Data>
</Cred>

What I'm trying to do is retrieve the text 'syncml:auth-basic' with
XPath and XmlNode.SelectSingleNode(). I thought that 'Meta/Type' would
do the trick but was wrong on that count. Next I tried
'Meta/syncml:metinf:Type' but was rong on that count too.

Can anyone shed any light on how to do this?

Cheers,

Mark.
Nov 12 '05 #1
1 1267
Hi,

with XmlDocument (and XmlNode) you'd use XmlNamespaceManager in conjuction
with custom namespace prefix to do it. here is an example that uses this XML
snippet as complete document (still illustrating how to do it)
---
'Load the XML into XmlDocument
Dim objDoc As New XmlDocument
objDoc.Load(Server.MapPath("XMLFile1.xml"))

'Create namespace manager with reference to XMlDoc's NameTable
Dim objMan As New XmlNamespaceManager(objDoc.NameTable)
objMan.AddNamespace("myprefix", "syncml:metinf")

'Locate the Cred node to be as close to your scenario as possible (you can
and you should query with one call to SelectSingleNode if possible, I am
doing this in two steps to illustrate on being in same context as you)
Dim objNode As XmlNode = objDoc.SelectSingleNode("Cred")

'Query the desired node using specific prefix (prefix is not important,
namespace URI is, therefore I could use any prefix that maps to the same
namespace URI)
Dim objResultNode As XmlNode =
objNode.SelectSingleNode("Meta/myprefix:Type", objMan)

---

Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Mark Snelling" <ma************************@ignore.this.com> wrote in
message news:vk**********************@news.easynews.com...
Hi,
I have a question regarding XPath and namespaces. I have a piece of XML...

<Cred>
<Meta>
<Type xmlns='syncml:metinf'>syncml:auth-basic</Type>
</Meta>
<Data>QnJ1Y2UyOk9oQmVoYXZl</Data>
</Cred>

What I'm trying to do is retrieve the text 'syncml:auth-basic' with
XPath and XmlNode.SelectSingleNode(). I thought that 'Meta/Type' would
do the trick but was wrong on that count. Next I tried
'Meta/syncml:metinf:Type' but was rong on that count too.

Can anyone shed any light on how to do this?

Cheers,

Mark.
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Sebastian Petzelberger | last post: by
reply views Thread by Bart | last post: by
2 posts views Thread by ree32 | last post: by
9 posts views Thread by David Thielen | last post: by
5 posts views Thread by Gnic | last post: by
7 posts views Thread by Tim Hallwyl | last post: by
reply views Thread by John Krukoff | last post: by
1 post views Thread by XIAOLAOHU | last post: by
1 post views Thread by ZEDKYRIE | last post: by

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.