in reply to How to use perl XML::LibXML Parser?

Here is an example using XML::LibXML. There are many ways to use the module but I find that Xpath expressions are really powerful once you get your head around them.
use XML::LibXML; my $string = q|<?xml version="1.0"?> <IPDetails> <productName>IBM Tivoli Workload Scheduler for Applications</product +Name> <vendorName>IBM</vendorName> <version>8.6.0.0</version> </IPDetails>|; my $tree = XML::LibXML->load_xml(string => $string); open (my $out_xml,">",'out.xml') or die "with nice message: $!"; print $out_xml qq|All the hardcoded stuff\n|; my @nodes = $tree->findnodes('/IPDetails'); for my $node (@nodes) { my $product_name = $node->findvalue('productName'); my $vendor_name = $node->findvalue('vendorName'); my $version = $node->findvalue('version'); print $out_xml qq|<Package Name="$product_name" Version="$version" +>\n|; print $out_xml qq|<Property Name="Publisher" Value="$vendor_name"> +\n|; print $out_xml qq|</Package>\n|; } print $out_xml qq|End stuff\n|; close $out_xml;

Replies are listed 'Best First'.
Re^2: How to use perl XML::LibXML Parser?
by Anonymous Monk on Mar 05, 2014 at 16:34 UTC

    Thanks tangent for your sample script. I liked it and however i used LibXML->parse_file method to parse the xml and used it's object to fetch the nodes and their values using text content method.

    Regards,

    Sriram