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

A

Abhinav

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
 
M

Martin Honnen

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
 
A

Abhinav

Martin said:
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
 
M

Martin Honnen

Abhinav said:
Martin said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top