f



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
0
Abhinav
7/29/2004 12:32:30 PM
comp.lang.perl.misc 33220 articles. 1 followers. brian (1246) is leader. Post Follow

4 Replies
910 Views

Similar Articles

[PageSpeed] 35


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/

0
Martin
7/29/2004 12:52:46 PM
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
0
Abhinav
7/29/2004 1:06:53 PM
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
0
Franck
7/29/2004 1:07:09 PM

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/

0
Martin
7/29/2004 1:13:27 PM
Reply: