XPath for selecting the text of an attribute

Discussion in 'XML' started by pjvleeuwen@gmail.com, May 19, 2008.

  1. Guest

    Hi all,

    For many of you this may be childishly simple, but the following
    problem keeps me wondering for almost two hours, so I hope any of you
    could point out what it is that I am doing wrong.

    Consider the following simple XML: <?xml version="1.0"?
    ><rootE><tagA>valueA</tagA><tagB attrB1="attrValueB1"

    attrB2="attrValueB2"/><tagC><tagCA/><tagCB/><tagCC><tagCCA/><tagCCA/
    ><tagCCB>60</tagCCB><tagCCC/></tagCC><tagCD/><tagCE/></tagC></rootE>


    Now I want to read the value "attrValueB2" so I tried writing a
    regular expression for it. I know that the following selects the
    attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
    @attrB2
    But I cant seem to select the value of this attribute. I get an empty
    string when quering /rootE/tagB/@attrB2/text()

    ANY suggestions? I cant see what I'm doing wrong. Everything seems to
    be fine in comparison with the tutorials I have seen and I tried all
    the lexical variations / alterations I could think of.

    Many thanks in advance for any suggestions!

    Cheers,
    Paul
    , May 19, 2008
    #1
    1. Advertising

  2. wrote:

    > Now I want to read the value "attrValueB2" so I tried writing a
    > regular expression for it. I know that the following selects the
    > attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
    > @attrB2
    > But I cant seem to select the value of this attribute. I get an empty
    > string when quering /rootE/tagB/@attrB2/text()


    Attributes in the XPath data model don't have any text child nodes.
    Simply use
    /rootE/tagB/@attrB2
    to select the attribute, then you would get the value in a way depending
    on the host language e.g. in XSLT with
    <xsl:value-of select="/rootE/tagB/@attrB2"/>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, May 19, 2008
    #2
    1. Advertising

  3. * wrote in comp.text.xml:
    >Now I want to read the value "attrValueB2" so I tried writing a
    >regular expression for it. I know that the following selects the
    >attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
    >@attrB2
    >But I cant seem to select the value of this attribute. I get an empty
    >string when quering /rootE/tagB/@attrB2/text()


    Use "string(/rootE/tagB/@attrB2)" though string() will be used
    implicitly in many cases and is consequently rarely necessary.
    --
    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, May 19, 2008
    #3
  4. Guest

    You where both right. Thank you very much. This clarifies a lot.
    Cheers,
    Paul

    On May 19, 1:08 pm, Bjoern Hoehrmann <> wrote:
    > * wrote in comp.text.xml:
    >
    > >Now I want to read the value "attrValueB2" so I tried writing a
    > >regular expression for it. I know that the following selects the
    > >attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
    > >@attrB2
    > >But I cant seem to select the value of this attribute. I get an empty
    > >string when quering /rootE/tagB/@attrB2/text()

    >
    > Use "string(/rootE/tagB/@attrB2)" though string() will be used
    > implicitly in many cases and is consequently rarely necessary.
    > --
    > 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/
    , May 19, 2008
    #4
    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. Alastair Cameron
    Replies:
    1
    Views:
    7,370
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  2. Mike Kamermans
    Replies:
    2
    Views:
    384
    David Carlisle
    Oct 18, 2004
  3. Replies:
    2
    Views:
    1,068
    Henry S. Thompson
    Mar 6, 2006
  4. =?ISO-8859-1?Q?Une_B=E9vue?=

    XPath selecting elements afer one having a given text

    =?ISO-8859-1?Q?Une_B=E9vue?=, Feb 22, 2007, in forum: XML
    Replies:
    1
    Views:
    751
    =?ISO-8859-1?Q?Une_B=E9vue?=
    Feb 22, 2007
  5. Thomas Schmidt
    Replies:
    7
    Views:
    1,120
    Thomas Schmidt
    Jul 19, 2007
Loading...

Share This Page