Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Reading and updating XML

by prashantktyagi (Scribe)
on Sep 12, 2013 at 12:01 UTC ( #1053701=perlquestion: print w/replies, xml ) Need Help??
prashantktyagi has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am newbie to XML Parsing.I am using XML::LibXML module to parse my XML. I want to read a XML (input.xml) and update the node in (output.xml).
here is my attempt--
my $parser = XML::LibXML->new(); $doc = $parser->parse_file("input.xml"); my $appName = $doc->findvalue(q|@name|);
So I have slurp whole file into $doc. Same way I have opened output.xml (complex one ) and did this way.
use XML::LibXML; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file("output.xml"); my $query = "//anonotaion"; my($node) = $doc->findnodes($query); $node->setData('$appname'); print $doc->toString;
output.xml format is completely different from input.xml. I would like to know if there is any good way to achieve this.
fraction of xmls is --
<appliance long_name ="my app name" revision=""> <desciption_section> <annotation>template</annotation> <add_eula enabled="1"> <description>EULA LICENSE AGREEMENT</description> </add_eula> <welcome_screen enabled="1">welcome to my app </welcome_screen> </desciption_section> .....
<?xml version="1.0" encoding="utf-8"?> <ovf:Envelope xmlns:xsi="" xm +lns:vadk="" xmlns:ovf="http://schema" xmlns:vssd=" +scim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:rasd="http:// +ingData" xmlns:vmw="" xmlns:vsm="http +://" xsi:schemaLocation="http:// /opt/vmware/etc/build/schemas/vadk.xs +d" ovf:version="0.7.0" vadk:version=""> <References> <File ovf:href="system.vmdk" ovf:id="system.vmdk_id"/> </References> <!-- The Annotation element of the AnnotationSection_Type is the te +xt that will be presented as the Description of the VM. --> <Section xsi:type="ovf:AnnotationSection_Type"> <Info/> <Annotation>new app</Annotation> </Section> <Section xsi:type="ovf:ProductSection_Type" ovf:required="false"> <Info>branding information</Info> <Product>OvMabk</Product> <Vendor></Vendor> ....

Replies are listed 'Best First'.
Re: Reading and updating XML
by choroba (Chancellor) on Sep 12, 2013 at 12:12 UTC
    Your XML seems to use namespaces. You should study XML::LibXML::XPathContext to handle them in XPath queries.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1053701]
Approved by hdb
[james28909]: yep, i am scraping a websites date/time stamp from an article. none of that is relevant though because the strings i get are as expected. the returned data from the website is the list of @weekdays
[james28909]: i need to convert those @weekdays to an numerical date based off of scalar localtime
[james28909]: i have thught about this and though about it lol
[james28909]: also remember, that if 'Today' is may 1, then Yesterday is not may 31 lol
[james28909]: theoretically speaking ofcourse

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2017-04-29 03:50 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (531 votes). Check out past polls.