XML XPath Perl Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akhilak
    New Member
    • May 2007
    • 2

    XML XPath Perl Help

    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">Na me Author</authordata>
    <address>name address</address>
    <publication>na me 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="au thorid";
    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.
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Well, you get the Blue Ribbon reward for the most obnoxious forum cross-poster in recent memory. Plus you never responded to the first question you ever posted on this forum:



    probably because you corss-posted it on other forums, got a reply and wasted the time of the people that replied here.

    Jeff, Miller, give this guy the boot.

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      Originally posted by KevinADC
      Well, you get the Blue Ribbon reward for the most obnoxious forum cross-poster in recent memory. Plus you never responded to the first question you ever posted on this forum:



      probably because you corss-posted it on other forums, got a reply and wasted the time of the people that replied here.

      Jeff, Miller, give this guy the boot.

      I have PM'd yourself and Miller about it and will await Miller's response.

      Regards,

      Jeff

      Comment

      Working...