X-path namespace sample and question

  • Thread starter Leonard T. Armstrong
  • Start date
L

Leonard T. Armstrong

I have an XML document that is structured similarly to the following
generalization:

<?xml version="1.0" encoding="UTF-8"?>
<A xmlns="urn:aaa-aaa-aaa:a-part">
<B>
<C xmlns="urn:ccc-ccc-ccc:c-part">
<D>1</D>
<D>2</D>
</C>
<C xmlns="urn:ccc-ccc-ccc:c-part">
<D>3</D>
<D>4</D>
</C>
</B>
<B>
<C xmlns="urn:ccc-ccc-ccc:c-part">
<D>5</D>
</C>
</B>
</A>

is there a simpler XPATH expression to grab all <D> elements than the
following?

//*[namespace-uri()='urn:ccc-ccc-ccc:c-part' and local-name()='D']

The problem seems to stem from the fact the the documents I am given do
not have namespace prefixes.

Any thoughts?

Thanks,
Leonard Armstrong
 
R

Richard Tobin

Leonard T. Armstrong said:
is there a simpler XPATH expression to grab all <D> elements than the
following?

//*[namespace-uri()='urn:ccc-ccc-ccc:c-part' and local-name()='D']

You need to bind a prefix to the namespace in the context of your
XPath. So if it appears in a stylesheet, bind a prefix in the
stylesheet.

-- Richard
 
L

Leonard T. Armstrong

Thanks Richard, but I should have clarified that the problem is not with an
XSLT stylesheet. I recognize that in that context I can do prefix binding an
all will be well with the world.

My question stems from the use of te XPath tool in XMLSpy, where all I have
is original XML document (over which I have no control) and the XPath tool
to do some quick analysis to verify XPath expression prior to developing an
XSLT.

Thanks for the response,.
-- Leonard

Richard Tobin said:
Leonard T. Armstrong said:
is there a simpler XPATH expression to grab all <D> elements than the
following?

//*[namespace-uri()='urn:ccc-ccc-ccc:c-part' and local-name()='D']

You need to bind a prefix to the namespace in the context of your
XPath. So if it appears in a stylesheet, bind a prefix in the
stylesheet.

-- Richard
 
J

Johannes Koch

Leonard said:
My question stems from the use of te XPath tool in XMLSpy, where all I have
is original XML document (over which I have no control) and the XPath tool
to do some quick analysis to verify XPath expression prior to developing an
XSLT.

You need prefixes in XPath, too. If the tool you use doesn't give you
the possibility to bind prefixes to namespaces -- which I don't know --
the tool is not applicable for your task.

[TOFU snipped]
 

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

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top