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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?Pekka_J=E4rvinen?=

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

    Hi,

    How I can find <?something ?stuff?

    XML:
    <Wix>
    <?define UpgradeCode="{f oobar-quux-xyzzy}"?>
    <?define Manufacturer="C ompany"?>
    <!-- update this ALWAYS -->
    <?define PackageCode="RE PLACE"?>
    </Wix>

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

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

    But PackageCode isn't necessary always third.
  • Bjoern Hoehrmann

    #2
    Re: XPath query for &lt;?define something=&quot ;something&quot ; ?&gt;

    * Pekka Järvinen wrote in comp.text.xml:
    >How I can find <?something ?stuff?
    >
    >XML:
    ><Wix>
    ><?define UpgradeCode="{f oobar-quux-xyzzy}"?>
    ><?define Manufacturer="C ompany"?>
    ><!-- update this ALWAYS -->
    ><?define PackageCode="RE PLACE"?>
    ></Wix>
    >
    >How to match that REPLACE with XPath? Or even better: find only define
    >and PackageCode
    >Doesn't work:
    >/Wix[processing-instruction('de fine[@PackageCode='R EPLACE']')]
    >/Wix[processing-instruction('de fine')/[@PackageCode='R EPLACE']/
    >@PackageCode]
    >/Wix[processing-instruction('de fine')/[@PackageCode='R EPLACE']]/
    >@PackageCode
    >/Wix[processing-instruction('de fine[@PackageCode='R EPLACE']')/]/
    >@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('de fine')[ . = 'PackageCode="R EPLACE"']

    This would find all <?define PackageCode="RE PLACE"?nodes. To parse
    the string value use functions like substring-before() and substring().
    --
    Björn Höhrmann · mailto:bjoern@h oehrmann.de · 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/

    Comment

    • Richard Tobin

      #3
      Re: XPath query for &lt;?define something=&quot ;something&quot ; ?&gt;

      In article <8f2016d4-05ce-4d55-887a-d0e9a36d7ca1@k1 3g2000hse.googl egroups.com>,
      Pekka Järvinen <pekka.jarvinen @gmail.comwrote :
      ><?define PackageCode="RE PLACE"?>
      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("de fine")[. = 'PackageCode="R EPLACE"']
      or
      processing-instruction("de fine")[contains(., "REPLACE")]

      -- Richard
      --
      :wq

      Comment

      Working...