codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  XML XPath Perl Help  akhilak at 16:37 on Saturday, September 08, 2007
 

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=>'/forum/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.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: repaint() slow performence..
•  To match on current line and the next line using perl?
•  Re: Text wrapping on C# webforms buttons
•  Increment revison when same item number
•  Re: Internet explorer doesnt load img on div
•  finger print reader?????
•  Re: How to concatenate a string and a variable using perl?
•  Re: questions on java
•  Frusturating loop


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007