473,562 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath question

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

<Cred>
<Meta>
<Type xmlns='syncml:m etinf'>syncml:a uth-basic</Type>
</Meta>
<Data>QnJ1Y2UyO k9oQmVoYXZl</Data>
</Cred>

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

Can anyone shed any light on how to do this?

Cheers,

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

with XmlDocument (and XmlNode) you'd use XmlNamespaceMan ager 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(Ser ver.MapPath("XM LFile1.xml"))

'Create namespace manager with reference to XMlDoc's NameTable
Dim objMan As New XmlNamespaceMan ager(objDoc.Nam eTable)
objMan.AddNames pace("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 SelectSingleNod e if possible, I am
doing this in two steps to illustrate on being in same context as you)
Dim objNode As XmlNode = objDoc.SelectSi ngleNode("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.SelectS ingleNode("Meta/myprefix:Type", objMan)

---

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

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

<Cred>
<Meta>
<Type xmlns='syncml:m etinf'>syncml:a uth-basic</Type>
</Meta>
<Data>QnJ1Y2UyO k9oQmVoYXZl</Data>
</Cred>

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

Can anyone shed any light on how to do this?

Cheers,

Mark.
Nov 12 '05 #2

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

Similar topics

7
16637
by: Sebastian Petzelberger | last post by:
Hi group, please give me an example of a xpath with regex or better a link with examples. Thanks in advance, Sebastian
0
1276
by: Bart | last post by:
Hello, I am real new to using LIBXML and have a question about XPATH evaluations. The question may show a real ignorance of the LIBXML structure, don't so assume I know what I am talking about. I am trying to use the XPATH functions to pull the data for individual data elements. The order of the elements whose value I must find are not...
3
4533
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method should result in a NodeSet". Of course, that (sort of) makes sense to me now (I suppose just an attribute couldn't be a nodeset, but how would I go
2
2870
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file - "xmlns="http://tempuri.org/nameOfRoot.xsd" I have no idea what its pointing to & what is tempuri.org? So when this tag is in my xml tag my xpath query never works. But...
9
2138
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example...
5
7919
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
7
2804
by: Tim Hallwyl | last post by:
Hi, there! As I understand the XPaht recommendation, the context node is a node; not a node-list, not XPath object -- but a single node. Now, the WS-BPEL 2.0 specification allows an XML simple type value to be the context of an XPath expression, by converting it to an XPath object -- either boolean, string or float. I do not see how...
0
1753
by: pompair | last post by:
Hello, I'm making a quiz game for fun. I have an xml file like this: <?xml version="1.0" encoding="utf-8" ?> <results> <index>99</index> <answers>11</answers> <questions> <question id="1">
0
1053
by: John Krukoff | last post by:
On Wed, 2008-09-03 at 13:36 -0700, bruce wrote: Well, you could just do the test (and the count!) in the xpath expression: count( //tr/td ) It sounds like you're not familiar with xpath? I would recommend the O'Reilly XSLT book, it has an excellent introduction to xpath in chapter 3.
0
7658
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7874
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7630
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7940
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6228
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3609
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1192
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
907
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.