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 32965 articles. 7 followers. brian (1246) is leader. Post Follow

4 Replies
630 Views

Similar Articles

[PageSpeed] 55

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:
Similar Artilces:

perl: warning: Setting locale failed.
Hello! I am using Debian, my packages are mixed stable/testing, and when I update packages using KPackage I get lots of perl warnings: > perl: warning: Setting locale failed. > perl: warning: Please check that your locale settings: > LANGUAGE = (unset), > LC_ALL = "en_US", > LANG = (unset) > are supported and installed on your system. > perl: warning: Falling back to the standard locale ("C"). Lots of these, and sometimes these: > locale: Cannot set LC_CTYPE to default locale: No such file or directory > locale: Cannot set LC_MESSAGES ...

FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? #19
This is an excerpt from the latest version perlfaq1.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 1.4: What are Perl 4, Perl 5, or Perl 6? (contributed by brian d foy) In short, Perl 4 is the past, Perl 5 is the present, and Perl 6 is the future. The number after Perl (i.e. the 5 after Perl 5) is the m...

MJD (of "Higher Order Perl") on Lisp macros
Copied from: http://lists.warhead.org.uk/pipermail/iwe/2005-July/000130.html (HOP itself has a very nice intro that refers to Lisp.) From: Mark Jason Dominus <mjd@plover.com> Date: Jul 28, 2005 11:16 PM Subject: Re: HOP -vs- SICP To: hop-discuss@plover.com Bennett Todd: > ... blinded by the superficial > ickiness of lisp (ref lwall "visual appeal of oatmeal with > fingernail clippings mixed in) As I think I said in the "Perl Review" interview, this is not just a matter of personal taste. Some people don't like Lisp syntax, but it has several major tech...

How to get PCI base address when I write custom driver for Real-time windows target?
I'm developing a PCI card driver for Real-Time Windows Target. It seems document doesn't has much information about that. I know how to write custom I/O driver for xPC target. xPC has some rountines to get the base address of PCI device and function to convert physical address to logical address. Does Real-Time Windows target have such function? I've written a part of code to read the PCI configuration space to get the physical base address of my card, but my card is memory mapped. It seems that I should convert it to linear address under protection mode. Thanks for your reading. ...

Perl search engine
A new search engine through a perl-related websites is opened: http://brainworker.ru/en/ Hope it would be useful useful to somebody. >>>>> "�" == �� <mayweed@gmail.com> writes: �> A new search engine through a perl-related websites is opened: �> http://brainworker.ru/en/ Hope it would be useful useful to somebody. the irony is that this was posted via google! but i bet the spammer won't get the irony. uri -- Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Trai...

Sunrocket Promo Code: 9145109100 -Get two free phones #4
www.sunrocket.com $199 per year for unlimited calls, 2 phone numbers, 2 free cool Uniden phones, moneyback guarantee, includes $3 free international calls per month, no other charges, no contract, free shipping, see full details at site Use promotion code 9145109100 under "ready to sign up?" ------------------------------------- ##-----------------------------------------------# Article posted with Cabling-Design.com Newsgroup Archiv http://www.cabling-design.com/forum no-spam read and post WWW interface to your favorite newsgroup - comp.dcom.voic...

Getting an IP Address as byte[]
From: file:///C:/apps/jakarta-tomcat-4.1.18/docs/javax/servlet/ServletRequest.html#getRemoteAddr() public java.lang.String getRemoteAddr(): Returns the Internet Protocol (IP) address of the client that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR. Returns: a String containing the IP address of the client that sent the request Now, this String should look like d.d.d.d for Inet4 or FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 for an Inet6 kind of address Now, where is a method in Java which, given an IP Address returns to you a byte[]. Four by...

FAQ 3.3 Is there a Perl shell? #14
This is an excerpt from the latest version perlfaq3.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 3.3: Is there a Perl shell? The psh (Perl sh) is currently at version 1.8. The Perl Shell is a shell that combines the interactive nature of a Unix shell with the power of Perl. The goal is a full featured shell...

Getting started on solaris/sun gear
Getting started with solaris and sun hardware. What recommendations can the group make for hardware. I will probally ebay a couple boxes. What should I look for.. ? Also, start with Sol10 or 9? TIA On Sun, 18 Jul 2004 01:09:31 +0000, netnews.comcast.net wrote: > Getting started with solaris and sun hardware. What recommendations can the > group make for hardware. I will probally ebay a couple boxes. What should I > look for.. ? Also, start with Sol10 or 9? TIA http://docs.sun.com http://sunsolve.sun.com/handbook_pub/ On Sun, 18 Jul 2004, netnews.comcast.net wrote: > Getting...

Anyone else getting SPAM?!
So, today I received some great news. Apparently, a user named Muhammad Sakir experienced a death in the family, and I am somehow entitled to his $12,500,000 estate. All I need to do is send a bunch of phone numbers for myself and my family, and some other personal information. Anybody else getting spam messages from their Author pages here? "Vince Petaccio" <vince@moberg.com> wrote in message <gpr6el$1h2$1@fred.mathworks.com>... > So, today I received some great news. Apparently, a user named Muhammad Sakir experienced a death in the family, and I am somehow entitle...

Sysread in perl
Hi, I am trying to read the last 500 bytes of a file. I'm trying to use sysread command, I have read the docs for it on cpan and it seems the right thing to use. My only problem is when i spcify a negative offset it fails with the following error "Offset outside string at test.pl line 30.". here is the line it is complaing about sysread(F,$string,500,-500); I have tried escaping the minus sign , putting it into a var and using eval and they all come back with the same error. Heres the paragraph from cpans docs "An OFFSET may be specified to place the read d...

Re: How to get last letter of variable name into new variable #7 694607
This solved the problem! Thanks, Roy Peter -----Original Message----- >From: "Pardee, Roy" <pardee.r@GHC.ORG> >Sent: Aug 7, 2007 12:14 PM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Re: How to get last letter of variable name into new variable > >So you want to do something like: > >Proc factor ; > var &d_variables ; >Run ; > >Proc factor ; > var &t_variables ; >Run ; > >Etc.? > >For that I would pull out my old favorite--sql query from >dictionary.columns with an INTO clause. Something like: > >Proc sql ;...

Re: SAS w/ PERL #4
Can't be too difficult. After all, David Cassell become a perl expert, and he was a statistician! ;> S -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of John Burton Sent: Monday, June 08, 2009 4:49 PM To: SAS-L@LISTSERV.UGA.EDU Subject: SAS w/ PERL Hi all, I've been contatced about an opportunity using both SAS and PERL. I have tons of SAS, but no PERL experience. How hard is PERL to pick up on the fly? Should not having it be a deal-breaker? -- Best Cheers, Ray Burton Chattanooga TN AnalyticBridge, Linked-In, MedZilla, SAS/L ...

Perl 5.004 bug
Can someone give me some guidance as to why the following code does not work in Perl 5.004, but does work in version 5.6? Note, the output below is produced from a cat -n on the actual file so the line numbers are not part of the actual program. I'm getting syntax errors on line 31 and 34 presumably from the for @buckets syntax. In addition, the sprintf command on line 27 doesn't appear to be working correctly. Is there something wrong with Perl 5.004 that would prevent the binary conversion? Can someone help me modify this so that it will work with version 5.004. Thanks a...

Why do I get an extra return in thie following case?
I just don't spend enough time "tinkering" with *nix. Anyhow when I read from an unbuffered input and type something in, I get two prompts after I hit return. m-net% more tty.c #include <stdio.h> int main(void) { char c; return(read(0, &c, 1) == 1) ? (unsigned char)c : EOF; return 0; } m-net% ./tty c m-net% m-net% Now when I buffer the input, and type something in, I only get one prompt after I hit return. m-net% more tty2.c #include <stdio.h> int main(void) { static char buf[BUFSIZ]; static char *bufp = buf; static int n = 0; if(n == 0) { n = rea...

Re: Get Data Back #9 692302
Hi Michael, I am working on a HP- UX machine. I had made the same table in another environment just a couple of days back and I remembered it after sending the mail to the SAS-L group. I copied the table and made a few changes that I remember would be necessary to make it operational. Till now the users/functional team have not complained so it seems things are on track :) Hope none of my functional team members are reading this post :P The next time I shall be more than cautious while working on the tables however when things need to be done quickly these types of incidents happen. I guess ...

[News] Samba Goes More Public, Mercurial Gets Another Adopter
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Doing the Samba in Public ,----[ Quote ] | It's a little hard to tell whether the statement “was offered an opportunity” | means that it was Microsoft who instigated the project, or whether it flows | from the earlier EU investigation into interoperability that led to | Microsoft's documentation being made available to Samba for a nominal sum. `---- http://www.computerworlduk.com/community/blogs/index.cfm?entryid=2428&blogid=14 Filmaster switches to Mercurial ,----[ Quote ] | Filmaster.com, the open source movie recommendatio...

how to catch a value from radio buttom getting its value from mysql?
Hi, this is a newbie question. How can I catch the selected radio value from a form that is feed by the mysql database? EX.: <input type="radio" name="myname" value="<?php $myvalue[3] ?>"> Value returns the last element of the array $myvalue[3] instead of the selected value. How can I change this? Thanks in advance for any help, Guillermina echo? <input type="radio" name="myname" value="<?php echo $myvalue[3] ?>"> PWT "gmanon" <guillermina@nyc.rr.com> wrote in messa...

Getting a MBP today :)
I'm getting my Mac Book Pro today. Out goes the old IBM Thinkpad. I'll keep you posted. -- regards , Peter B. P. - http://titancity.com/blog http://markedspartiet.dk, http://macplanet.dk http://siad.dk In article <1hp3o38.lru49kbnf52uN%peter@DIESPAMMERDIE.dk>, peter@DIESPAMMERDIE.dk (Peter Bj�rn Perls�) wrote: > I'm getting my Mac Book Pro today. I'm still waiting for my package, which would take somewhere around 5-7 weeks, proobably due to the quadro FX graphics in the mac pro. -- Sandman[.net] Peter Bj�rn Perls� <peter@DIESPAMMERDIE.dk> wrote: >...

SELECT TOP 10 -- then get next 10?
I need to do a query and limit it to returning 10 rows at a time. I can't rely on dynamic cursors or anything like that because I can't keep a cursor open between each query. I know I can use "SELECT TOP 10" in my SQL statement to get the first 10. But after that, is there any easy way to get rows 11 to 20 (the next 10)? If my query had a simple ORDER BY I know one way I could solve the problem. For example, if it was "ORDER BY ID", then I would just include "WHERE ID > X" (X would be the highest ID returned in the previous query). However, my ORD...

FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? #4
This is an excerpt from the latest version perlfaq2.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 2.17: What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? Perl.com at http://www.perl.com/ is part of the O'Reilly Network, a subsidiary of O'Reilly Media. The Perl Foundation is an advocacy org...

Re: Cheapest Way to Get SAS #4
On Thu, 19 Apr 2007 09:43:18 -0400, ben.powell@CLA.CO.UK wrote: >On Thu, 19 Apr 2007 08:36:36 -0400, paul <pdick99@YAHOO.COM> wrote: > >>Hi SAS-L, >> >>Work in London and where I am working doesn't have sasv9 and don't want to >>be left behind in the SAS Market. I am looking to find the cheapest way of >>getting a version of SAS v9. >> >>Cheers, >>Paul. > >SAS learning edition on Amazon, limited to 1000 obs or so. Otherwise >probably circa £1500+ first year, > >Rgds. The "cheepest" way, is to s...

25.2.12 Partions: return values stated strangely
ISO/IEC 14882:2003 says: 25.2.12 Partitions template<class BidirectionalIterator, class Predicate> BidirectionalIterator partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred); 2 Returns: An iterator i such that for any iterator j in the range [first, i), pred(*j) != false, and for any iterator k in the range [i, last), pred(*j) == false. template<class BidirectionalIterator, class Predicate> BidirectionalIterator stable_partition(BidirectionalIterator first, BidirectionalIterator last, P...

unix pipes to perl scripts
Got a problem piping command output to a perl script, in the test below the loop accepts the piped files but it also interferes with my STDIN! ===test============================= $ls -1 *.cfg | ./pp file: hosts.cfg file: pseries.cfg type something : you typed : ===test============================= I do not get the chance to type something in after "type something"... Do i have to flush some variable inbetween the foreach loop and <STDIN>? Is looping trough <ARGV> or <> the best way to catch piped input? ===code============================= $cat ./pp #!/usr/bin...

How can I get the centroid of a convex hull
Hi, I have used the function 'convhull' to get the points of the convex hull. Now I need to find the centroid of this convex hull. Which function can I use? Thanks. <daiwen.v@gmail.com> wrote in message news:1175194158.129881.89980@e65g2000hsc.googlegroups.com... > Hi, > I have used the function 'convhull' to get the points of the convex > hull. Now I need to find the centroid of this convex hull. Which > function can I use? > Thanks. > I think I might try solving symbolically for the centroid of a triangle and then pick a point in the middle and mak...