regex xpath expressions

T

Timo Nentwig

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
 
D

Dimitre Novatchev

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
 
T

Timo Nentwig

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>
 
M

Mats Kindahl

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
--
IAR Systems in Uppsala, Sweden.

Any opinions expressed are my own and not those of my company.

Spam prevention: contact me at (e-mail address removed) or
(e-mail address removed), removing the *NO SPAM* from the address.
 
D

Dimitre Novatchev

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top