Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath query for <?define something="something" ?>

Reply
Thread Tools

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

 
 
Pekka Järvinen
Guest
Posts: n/a
 
      04-29-2008
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.
 
Reply With Quote
 
 
 
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      04-29-2008
* 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().
--
Björn Höhrmann · (E-Mail Removed) · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      04-29-2008
In article <(E-Mail Removed)>,
Pekka Järvinen <(E-Mail Removed)> wrote:

><?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
--
:wq
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
xpath query query David Gordon XML 2 05-18-2005 03:33 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments