I am new to XML parsing writing so be gentle... :) I have the following bit of XML I want to read in and and spit back out in exactly the same form but with different values:
<?xml version="1.0" encoding="utf-8"?> <AttributeDatabase> <attribclass toolonly="false" hidden="false" dbvault="true"> <editlist name="default"> <entry>*</entry> </editlist> <preferrededitlist>"default"</preferrededitlist> <attribdef name="mtl_param" synthetic="true" array="true"> <desc>IsSynthetic</desc> <type>Attrib.Types.Vector4</type> <bound>True</bound> <properties platform="common"> <mincount>2</mincount> <maxcount>2</maxcount> </properties> </attribdef> <attribdef name="mtl_Kdiff" toolonly="true"> <memberkeyvalue path="" key="push(bits)-&gt;::mtl_param:common +:0:w" /> <desc>controls --&gt; mtl_param[0].w </desc> <type>EA.Reflection.Float</type> <bound>False</bound> <increment>0.001</increment> <properties platform="common"> <max>2.0</max> <min>0.0</min> <defaultreflectedobject>1.0</defaultreflectedobject> </properties> </attribdef> </attribclass> </AttributeDatabase>
I have no problem reading things in with XML-Simple
my $fh; open( $fh , "<", $arg{file}) or die; my $xml = XML::Simple->new(KeepRoot=>1) ; my $xml_data = $xml->XMLin($fh);
I do stuff to it... and then go to write it out thus:
my $xml = XML::Simple->new(XMLDecl=>1,KeepRoot=>1) ; my $xml_data = $xml->XMLout($arg{data});
but no matter which options I try with XML-Simple I can't reconstruct the same XML output as input. The closest I have come is:
<?xml version='1.0' standalone='yes'?> <AttributeDatabase> <attribclass> <attribdef> <name>mtl_Kdiff</name> <bound>False</bound> <desc>controls --&gt; mtl_param[0].w </desc> <increment>0.001</increment> <memberkeyvalue> <key>push(bits)-&gt;::mtl_param:common:0:w</key> <path></path> </memberkeyvalue> <properties> <defaultreflectedobject>1.0</defaultreflectedobject> <max>2.0</max> <min>0.0</min> <platform>common</platform> </properties> <toolonly>true</toolonly> <type>EA.Reflection.Float</type> </attribdef> <attribdef> <name>mtl_param</name> <array>true</array> <bound>True</bound> <desc>IsSynthetic</desc> <properties> <maxcount>2</maxcount> <mincount>2</mincount> <platform>common</platform> </properties> <synthetic>true</synthetic> <type>Attrib.Types.Vector4</type> </attribdef> <dbvault>true</dbvault> <editlist> <name>default</name> <entry>*</entry> </editlist> <hidden>false</hidden> <preferrededitlist>&quot;default&quot;</preferrededitlist> <toolonly>false</toolonly> </attribclass> </AttributeDatabase>
Notice how the embedded element attributes in the attribclass and attribdef tags drop out. and my quotes(") become &quot; or drop out altogether... Does anyone know how to keep some attributes from dropping out of element tags and others let go? I am afraid I am gonna have to write out each element as I traverse the data structure so that can control the output of XMLout(). Anyone got any advice? Your humble DTD Destroyer, jmm

In reply to XML gurus unite!! by jmmistrot

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.