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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top