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

Discussion in 'XML' started by Pekka Järvinen, Apr 29, 2008.

  1. 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.
    Pekka Järvinen, Apr 29, 2008
    #1
    1. Advertising

  2. * 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 · mailto: · 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/
    Bjoern Hoehrmann, Apr 29, 2008
    #2
    1. Advertising

  3. In article <>,
    Pekka Järvinen <> 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
    Richard Tobin, Apr 29, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jake
    Replies:
    0
    Views:
    348
  2. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    789
    David Gordon
    May 18, 2005
  3. theotyflos
    Replies:
    3
    Views:
    469
    Thomas Matthews
    Feb 19, 2004
  4. robin liu
    Replies:
    3
    Views:
    821
    Robin Liu
    Apr 21, 2006
  5. Brian Takita

    #define _ and #define __

    Brian Takita, Jan 23, 2006, in forum: Ruby
    Replies:
    0
    Views:
    460
    Brian Takita
    Jan 23, 2006
Loading...

Share This Page