looking for an an XPath/XQuery equivalent to a regexp pattern

S

S Perryman

Hello there.

I'm trying to construct an XPath/XQuery expression to find all
elements in an XML structure (descendents etc) that satisfy an infix
search pattern that in regexp form would be : *pattern* .

All the refs I've got to date suggest that I might only be able
to do :

*pattern (suffix match)
pattern* (prefix match)

Any info or ptrs etc would be much appreciated.


Regards,
Steven Perryman
 
M

Martin Honnen

S said:
I'm trying to construct an XPath/XQuery expression to find all
elements in an XML structure (descendents etc) that satisfy an infix
search pattern that in regexp form would be : *pattern* .

All the refs I've got to date suggest that I might only be able
to do :

*pattern (suffix match)
pattern* (prefix match)

It is not clear to me what you want to achieve. Do you want to find
elements where the name matches a certain pattern? Or elements where the
contents matches a certain pattern?

Also XPath 2.0 and XQuery 1.0 have regular expression support so you
could do e.g.
//*[matches(., 'someregularexpressionhere')]
to find all elements containing a string matching the regular expression
provided in the second argument to the matches function.

http://www.w3.org/TR/xpath-functions/#func-matches
 
S

S Perryman

Martin said:
It is not clear to me what you want to achieve. Do you want to find
elements where the name matches a certain pattern? Or elements where the
contents matches a certain pattern?

Looking for elements only. So :

<x-y-pattern-z>
<x-pattern>
etc

I will try the expr you gave me (thanks) .


Regards,
Steven Perryman
 
M

Martin Honnen

S said:
Looking for elements only. So :

<x-y-pattern-z>
<x-pattern>

So you want to match on the element name, not the contents.
I will try the expr you gave me (thanks) .

The example I presented matches on the element contents, not the name.
If you want to match on the name you are left with
//*[matches(local-name(), 'regularexpressiongoeshere')]
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top