469,366 Members | 2,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

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

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
Jul 20 '05 #1
4 45648


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/

Jul 20 '05 #2
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
Jul 20 '05 #3
Abhinav wrote:

Any docs (apart from the CPAN XPath docs) which detail these concepts
more clearly ?
Google is your friend :

http://www.w3schools.com/xpath/default.asp

And the official W3C reccomendation :

http://www.w3.org/TR/xpath

Franck,e-

TIA

--

Abhinav

Jul 20 '05 #4


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/

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by bdinmstig | last post: by
2 posts views Thread by David Gordon | last post: by
3 posts views Thread by SD | last post: by
2 posts views Thread by akhilak | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.