XPath query for <?define something="something" ?>

P

Pekka Järvinen

Hi,

How I can find <?something ?> stuff?

XML:
<Wix>
<?define UpgradeCode="{foobar-quux-xyzzy}"?>
<?define Manufacturer="Company"?>
<!-- update this ALWAYS -->
<?define PackageCode="REPLACE"?>
</Wix>

How to match that REPLACE with XPath? Or even better: find only define
and PackageCode
Doesn't work:
/Wix[processing-instruction('define[@PackageCode='REPLACE']')]
/Wix[processing-instruction('define')/[@PackageCode='REPLACE']/
@PackageCode]
/Wix[processing-instruction('define')/[@PackageCode='REPLACE']]/
@PackageCode
/Wix[processing-instruction('define[@PackageCode='REPLACE']')/]/
@PackageCode

Works:
/Wix[processing-instruction('define')[3]]

But PackageCode isn't necessary always third.
 
B

Bjoern Hoehrmann

* Pekka Järvinen wrote in comp.text.xml:
How I can find <?something ?> stuff?

XML:
<Wix>
<?define UpgradeCode="{foobar-quux-xyzzy}"?>
<?define Manufacturer="Company"?>
<!-- update this ALWAYS -->
<?define PackageCode="REPLACE"?>
</Wix>

How to match that REPLACE with XPath? Or even better: find only define
and PackageCode
Doesn't work:
/Wix[processing-instruction('define[@PackageCode='REPLACE']')]
/Wix[processing-instruction('define')/[@PackageCode='REPLACE']/
@PackageCode]
/Wix[processing-instruction('define')/[@PackageCode='REPLACE']]/
@PackageCode
/Wix[processing-instruction('define[@PackageCode='REPLACE']')/]/
@PackageCode

These do not work because the processing instruction data is simply a
string, there are no attributes, they just look like them. You have to
access the data by querying the PI's string value, so e.g.

//processing-instruction('define')[ . = 'PackageCode="REPLACE"']

This would find all <?define PackageCode="REPLACE"?> nodes. To parse
the string value use functions like substring-before() and substring().
 
R

Richard Tobin

Pekka Järvinen said:
<?define PackageCode="REPLACE"?>

The stuff in the <?define ... ?> is not an attribute. It's just some
text that looks like an attribute. You can match it as text:

processing-instruction("define")[. = 'PackageCode="REPLACE"']
or
processing-instruction("define")[contains(., "REPLACE")]

-- 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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top