Retrieving XML attribute using XML::XPath::Node::Attribute
am 28.06.2005 14:02:58 von vikrant
Hi
I am trying to retrieve an attribute of a particular node from my XML
using "XML::XPath::Node::Attribute", but couldn't come across on how to
successfully use it in my code. For example, if my xml is:
10.0.0.1
How do I go about fetching the "port" attribute from "server_address"
element?
Vikrant
Re: Retrieving XML attribute using XML::XPath::Node::Attribute
am 29.06.2005 10:04:02 von arcofdescent
vikrant wrote:
>
>
>
> 10.0.0.1
>
>
> How do I go about fetching the "port" attribute from "server_address"
> element?
>
I'm never used XML::XPath::Node::Attribute, but what you want is
very easily possible using XML::Parser
--
Rohan
Re: Retrieving XML attribute using XML::XPath::Node::Attribute
am 29.06.2005 13:06:26 von Michel Rodriguez
vikrant wrote:
> I am trying to retrieve an attribute of a particular node from my XML
> using "XML::XPath::Node::Attribute", but couldn't come across on how to
> successfully use it in my code. For example, if my xml is:
>
>
>
> 10.0.0.1
>
>
> How do I go about fetching the "port" attribute from "server_address"
> element?
Use a regular XPath query, ending with @port to get the port attribute:
#!/usr/bin/perl
use strict;
use warnings;
use XML::XPath;
my $xp = XML::XPath->new( ioref => \*DATA);
print "port: ", $xp->findvalue('/data/server_address/@port'), "\n";
__DATA__
10.0.0.1
Re: Retrieving XML attribute using XML::XPath::Node::Attribute
am 29.06.2005 16:00:43 von vikrant
vikrant wrote:
> Hi
>
> I am trying to retrieve an attribute of a particular node from my XML
> using "XML::XPath::Node::Attribute", but couldn't come across on how to
> successfully use it in my code. For example, if my xml is:
>
>
>
> 10.0.0.1
>
>
> How do I go about fetching the "port" attribute from "server_address"
> element?
>
> Vikrant
>
Thanks for the information
vikrant