in reply to XML::Simple problems

I was able to get XML::Simple to read in that data just fine. However, I did notice that your opening "declaration" tag was missing the ">" at the end of that line. Not sure if that is missing in your original data or if this was a just a "cut & paste" mistake in your post.

Here's the contents of sample.xml:

<declaration dd:maxOccur="-1" dd:minOccur="0" dd:nullType="exclude"> <contentDeclaration dd:minOccur="0" dd:nullType="exclude"/> <value dd:minOccur="0" dd:nullType="exclude"/> </declaration>

Here's the code I ran:

use strict; use warnings; use XML::Simple; use Data::Dumper; my $xml = XMLin('sample.xml'); print Dumper($xml);

And here's the output:

$VAR1 = { 'dd:minOccur' => '0', 'contentDeclaration' => { 'dd:minOccur' => '0', 'dd:nullType' => 'exclude' }, 'value' => { 'dd:minOccur' => '0', 'dd:nullType' => 'exclude' }, 'dd:maxOccur' => '-1', 'dd:nullType' => 'exclude' };

Replies are listed 'Best First'.
Re^2: XML::Simple problems
by zwon (Abbot) on Dec 27, 2011 at 16:45 UTC

    And by the way, passing result to XMLout produces original XML:

    XMLout($xml, RootName => 'declaration');

    returns

    <declaration dd:maxOccur="-1" dd:minOccur="0" dd:nullType="exclude"> <contentDeclaration dd:minOccur="0" dd:nullType="exclude" /> <value dd:minOccur="0" dd:nullType="exclude" /> </declaration>
Re^2: XML::Simple problems
by norricorp (Initiate) on Dec 27, 2011 at 18:09 UTC
    Sorry that was a cut and paste mistake. The snippet I posted is part of a much larger file. Most elements are converted to hashes and arrays but there are several which are empty. I did try reading and printing with LibXML and it did read the processing instructions and the "empty elements" that Simple had were properly completed. So perhaps that is a better alternative ....