CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
perl XML Xpath help

 



akhilak
Novice

Sep 8, 2007, 9:16 AM

Post #1 of 2 (399 views)
perl XML Xpath help Can't Post

Hi,

I am using XPath to retrieve the node data from an XML file. I used the following code to extract the attribute data from the file. I manually entered the attribute name in the code and I am able to extract the data properly. But when I tried to read the attribute name into a variable and use this variablename instead of actual data it is giving me errors.

Here is my XML file:
<book>
<authordata authorid="1">Name Author</authordata>
<address>name address</address>
<publication>name publication</publication>
</book>

Code with manually entered attribute name:
my $read = XML::XPath->new(filename=>'sample.xml');
my $nodedata = $read->find('//@authorid');

Code with the variablename:
$authoridno="authorid";
my $nodedata=$read->find('//$authoridno');

Could anyone please help me with this and also what should i do to extract nodename instead of attribute name in the code. Mean what should i do to extract the data inside the node authordata in the XML file. I'm doing this because ill be parsing the dtd and ill use the nodename to extract the respective data in the node.
Thanks in advance.


KevinR
Veteran


Sep 8, 2007, 9:55 AM

Post #2 of 2 (397 views)
Re: [akhilak] perl XML Xpath help [In reply to] Can't Post

Please don't cross-post your question like that again. Very obnoxious. Your question has been answered on another forum.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives