Perl XPath : How to get the value of the attribute?

Discussion in 'XML' started by Abhinav, Jul 29, 2004.

  1. Abhinav

    Abhinav Guest

    Hi,

    I have the following XML :

    <checkIn bug="1111111">
    <regression>
    </regression>
    </checkIn>

    How do i get the value "1111111" for bug ?

    I am able to get everything under <checkIn> using

    my $bug = $xPath->find("/checkIn[\@bug]");

    TIA
    --

    Abhinav
     
    Abhinav, Jul 29, 2004
    #1
    1. Advertising

  2. Abhinav wrote:


    > I have the following XML :
    >
    > <checkIn bug="1111111">
    > <regression>
    > </regression>
    > </checkIn>
    >
    > How do i get the value "1111111" for bug ?
    >
    > I am able to get everything under <checkIn> using
    >
    > my $bug = $xPath->find("/checkIn[\@bug]");


    I don't use Perl, but the XPath should be
    /checkIn/@bug

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jul 29, 2004
    #2
    1. Advertising

  3. Abhinav

    Abhinav Guest

    Martin Honnen wrote:
    >
    > Abhinav wrote:
    >
    >
    >
    >>I have the following XML :
    >>
    >><checkIn bug="1111111">
    >> <regression>
    >> </regression>
    >></checkIn>
    >>
    >>How do i get the value "1111111" for bug ?
    >>
    >>I am able to get everything under <checkIn> using
    >>
    >>my $bug = $xPath->find("/checkIn[\@bug]");

    >
    >
    > I don't use Perl, but the XPath should be
    > /checkIn/@bug
    >


    Thanks. That Worked !

    I guess the extra / allows me to fetch only the node containing the
    attribute ?

    Any docs (apart from the CPAN XPath docs) which detail these concepts more
    clearly ?

    TIA

    --

    Abhinav
     
    Abhinav, Jul 29, 2004
    #3
  4. Franck Guillaud, Jul 29, 2004
    #4
  5. Abhinav wrote:

    > Martin Honnen wrote:
    >
    >>
    >> Abhinav wrote:
    >>
    >>
    >>
    >>> I have the following XML :
    >>>
    >>> <checkIn bug="1111111">
    >>> <regression>
    >>> </regression>
    >>> </checkIn>
    >>>
    >>> How do i get the value "1111111" for bug ?
    >>>
    >>> I am able to get everything under <checkIn> using
    >>>
    >>> my $bug = $xPath->find("/checkIn[\@bug]");

    >>
    >>
    >>
    >> I don't use Perl, but the XPath should be
    >> /checkIn/@bug
    >>

    >
    > I guess the extra / allows me to fetch only the node containing the
    > attribute ?


    No, it selects the attribute node itself,
    /checkIn
    selects the <checkIn> root element,
    /checkIn/@*
    selects all its attribute nodes, and
    /checkIn/@bug
    selects the attribute with name bug

    > Any docs (apart from the CPAN XPath docs) which detail these concepts
    > more clearly ?


    There is the XPath 1.0 specification:
    http://www.w3.org/TR/xpath
    And there are tutorials, see
    http://www.w3schools.com/xpath/default.asp
    for instance.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jul 29, 2004
    #5
    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,527
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  2. Replies:
    2
    Views:
    1,097
    Henry S. Thompson
    Mar 6, 2006
  3. Replies:
    1
    Views:
    4,419
    Joe Kesselman
    Aug 2, 2006
  4. Replies:
    8
    Views:
    537
  5. Abhinav
    Replies:
    4
    Views:
    111
    Martin Honnen
    Jul 29, 2004
Loading...

Share This Page