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 --
__input.xml__
<appliance long_name ="my app name" revision="10.58.226.13"> <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> .....
__output.xml__
<?xml version="1.0" encoding="utf-8"?> <ovf:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xm +lns:vadk="http://www.vmware.com/schema/vadk" xmlns:ovf="http://schema +s.dmtf.org/ovf/envelope/1" xmlns:vssd="http://schemas.dmtf.org/wbem/w +scim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:rasd="http:// +schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSett +ingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:vsm="http +://www.vmware.com/schema/vServiceManager" xsi:schemaLocation="http:// +schemas.dmtf.org/ovf/envelope/1 /opt/vmware/etc/build/schemas/vadk.xs +d" ovf:version="0.7.0" vadk:version="2.6.0.0"> <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> ....

In reply to Reading and updating XML by prashantktyagi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.