xpath expression

S

shapper

Hello,

I am trying to use an XPath to select siteMapNode nodes where
footer=true.
What I have is:
siteMapNode[@footer='true']

It is not working.
My XML document is:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap
xmlns = "http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode
url = "~/Default.aspx"
title = "Home"
description = "Desc1"
footer = "true" />
<siteMapNode
url = "~/Contacts.ASPx"
title = "Contactos"
description = "Desc2"
footer = "true" />
</siteMapNode>
</siteMap>

Could someone help me out?

Thanks,
Miguel
 
M

Martin Honnen

R

Richard Tobin

shapper said:
I am trying to use an XPath to select siteMapNode nodes where
footer=true.
What I have is:
siteMapNode[@footer='true']
<siteMap
xmlns = "http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode
url = "~/Default.aspx"
title = "Home"
description = "Desc1"
footer = "true" />

Your <siteMapNode> elements are in the

http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0

namespace, so you have to do the same for your XPaths. XPath doesn't
use the default namespace so you'll have to declare a prefix and use
that, e.g.

sm:siteMapNode[@footer='true']

You haven't said what program you're using with these XPaths, so I
can't tell you how to declare the prefix. If it is in an XSLT
stylesheet, you can just declare it on the <xsl:stylesheet> element.
If you calling some XPath library, it will have a way to do it.

-- Richard
 
S

shapper

Hello,

I am using VB.Net / Asp.Net to access my XML file.
The XPath is in my VB.Net code.

Thanks,
Miguel

Richard said:
shapper said:
I am trying to use an XPath to select siteMapNode nodes where
footer=true.
What I have is:
siteMapNode[@footer='true']
<siteMap
xmlns = "http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode
url = "~/Default.aspx"
title = "Home"
description = "Desc1"
footer = "true" />

Your <siteMapNode> elements are in the

http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0

namespace, so you have to do the same for your XPaths. XPath doesn't
use the default namespace so you'll have to declare a prefix and use
that, e.g.

sm:siteMapNode[@footer='true']

You haven't said what program you're using with these XPaths, so I
can't tell you how to declare the prefix. If it is in an XSLT
stylesheet, you can just declare it on the <xsl:stylesheet> element.
If you calling some XPath library, it will have a way to do it.

-- Richard
 
J

Joe Kesselman

shapper said:
I am using VB.Net / Asp.Net to access my XML file.
The XPath is in my VB.Net code.

You'll have to look at the documentation for your XPath API to find out
how to tell it what the namespace bindings are. I don't go near VB or
..Net so I can't give you more specific advice.

XPaths are namespace-aware. You have to work with that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top