regex xpath expressions

Timo Nentwig

Usenet Archive
Joined
Sep 21, 2002
Messages
195
Reaction score
0
Hi!

Seems that * cannot stand for non-existing nodes, i.e.

/html/*/title

will not match

<html>
<title>won't match</title>
</html>

Isn't it possible to write a xpath that will match the above as well as <title> encapsulated in <head> (except exp1 | exp2 | expN)?

Regards,
Timo
 

Dimitre Novatchev

Usenet Archive
Joined
Nov 7, 2000
Messages
737
Reaction score
0
Timo Nentwig said:
Hi!

Seems that * cannot stand for non-existing nodes, i.e.

Of course not. It would save time to read a good text in XPath before asking such kind of questions.
/html/*/title

will not match

An XPath expression does not "match" -- it selects.
<html>
<title>won't match</title>
</html>

Isn't it possible to write a xpath that will match the above as well as <title> encapsulated in <head> (except exp1 | exp2 | expN)?

The above is not well-formed xml.

What do you mean?

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
 

Timo Nentwig

Usenet Archive
Joined
Sep 21, 2002
Messages
195
Reaction score
0
Dimitre said:
The above is not well-formed xml.

Sure it is. But this doesn't matter anyway.
What do you mean?

I want one xpath that will select <td> in both cases:

<table>
<tbody>
<tr><td>...
</tbody>
</table>

<table>
<tr><td>...
</table>
 

Mats Kindahl

Usenet Archive
Joined
Sep 1, 2003
Messages
6
Reaction score
0
Timo Nentwig said:
Sure it is. But this doesn't matter anyway.

I want one xpath that will select <td> in both cases:

<table>
<tbody>
<tr><td>...
</tbody>
</table>

<table>
<tr><td>...
</table>

The XPath expression 'table//td' will match any 'td' with a 'table' node as ancestor.

Best wishes,
Mats Kindahl
 

Dimitre Novatchev

Usenet Archive
Joined
Nov 7, 2000
Messages
737
Reaction score
0
Timo Nentwig said:
Sure it is. But this doesn't matter anyway.

That certainly matters!
I want one xpath that will select <td> in both cases:

<table>
<tbody>
<tr><td>...
</tbody>
</table>

<table>
<tr><td>...
</table>

These are not well-formed xml documents.

An XPath expression can only be evaluated against a well-formed xml document.

Unless you provide such, your question has no meaning.

So I have to guess what would be the well-formed xml document you had in mind.

In case you meant:

<table>
<tbody>
<tr><td/></tr>
</tbody>
</table>

and

<table>
<tr><td/></tr>
</table>

Then one XPath expression (there are many!) thatselects the "td" element in both cases is:

/table/td | /table/tr/td

Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
 

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
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top