XPath performance w/ Namespaces

J

Jim

Hi,

When using an XPath query on an XML document that contains namespaces,
is there a more efficient way to find a node set based on the local
name than

//*[local-name()='MYNAME']

Is there another syntax that avoids using a predicate?

Thanks!

Jim
 
J

Johannes Koch

Jim said:
Hi,

When using an XPath query on an XML document that contains namespaces,
is there a more efficient way to find a node set based on the local
name than

//*[local-name()='MYNAME']

Is there another syntax that avoids using a predicate?

Register a prefix for the namespace in your XPath engine (how this is
done depends on the engine, have a look at the documentation) and use
this namespace in the XPath.
 
R

Richard Tobin

Jim said:
When using an XPath query on an XML document that contains namespaces,
is there a more efficient way to find a node set based on the local
name than

//*[local-name()='MYNAME']

Is there another syntax that avoids using a predicate?

No, but do you really want to do it? Doing something to all elements
with a certain local name regardless of their namespace seems like
a hack to me.

And I'd be surprised if the difference in efficiency is noticeable,
though //*:MYNAME (if it were allowed) would certainly be more readable.

-- Richard
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top