Ask a Question related to Brainstorming Area, Design and Development.
-
Unregistered #1
Element thrown away by XML::Simple
I am not expert enough in XML to know for 100% sure, but I don't think my file is "mixed" and still XML::Simple throws away attributes when I write out the object. I've stripped it down as much as possible here for example purposes:
stripped_xml.pl:
#!/usr/bin/perl
use XML::Simple;
use Data:
umper;
my ( $ref_XML_file, $out_XML_file, $dump_file ) = @ARGV;
my $XML_declaration = "<?xml version='1.0' encoding='UTF-8'?>";
open( OUT_XML_FILE, ">$out_XML_file" ) or die "Cannot open $out_XML_file for writing: $!";
open( DUMP_FILE, ">$dump_file" ) or die "Cannot open $out_XML_file for writing: $!";
my $xml = new XML::Simple;
my $xml_ref_hashref = $xml->XMLin($ref_XML_file, KeepRoot => 1 );
print DUMP_FILE Dumper( $xml_ref_hashref ), "\n";
print OUT_XML_FILE $xml->XMLout( $xml_ref_hashref, XmlDecl => $XML_declaration, KeepRoot => 1, NoAttr => 1 );
======================================
test_case.xml:
<?xml version='1.0' encoding='UTF-8'?>
<rootTag name='NameGoesHere' version='1.0'>
<ListOfThings thingID='40DD9' otherID='8026' isAThing='true' thingName='xyz123'>
<thingStuff >
<moreThingStuff isStuff='true' name='THX1138' duration='86400' />
</thingStuff>
</ListOfThings>
</rootTag>
If I run ./stripped_test.pl ./test_case.xml ./out.xml ./dump.txt
I get:
out.xml:
<?xml version='1.0' encoding='UTF-8'?>
<rootTag>
<name>NameGoesHere</name>
<ListOfThings>
<isAThing>true</isAThing>
<otherID>8026</otherID>
<thingID>40DD9</thingID>
<thingName>xyz123</thingName>
<thingStuff>
<name>THX1138</name>
<duration>86400</duration>
<isStuff>true</isStuff>
</thingStuff>
</ListOfThings>
<version>1.0</version>
</rootTag>
NOTE THAT "moreThingStuff" has completely disappeared.
Here is the dump file:
$VAR1 = {
'rootTag' => {
'ListOfThings' => {
'otherID' => '8026',
'thingID' => '40DD9',
'thingName' => 'xyz123',
'thingStuff' => {
'moreThingStuff' => {
'isStuff' => 'true',
'name' => 'THX1138',
'duration' => '86400'
}
},
'isAThing' => 'true'
},
'version' => '1.0',
'name' => 'NameGoesHere'
}
};
Is there a simple way to preserve this element on write-out? Or have I run into a bug? Or is this just not "simple" enough a structure for XML::Simple and I have to use something else? (If the latter, suggestions gratefully accepted.)Unregistered Guest
-
Are duplicate graphics thrown away?
Hi, I am working on a project that requires the pdf to be 8 MB or smaller for the client and its employees to download from a website and print on... -
A License Exception has been thrown.
A License Exception has been thrown. You tried to access the developer edition from a disallowed IP (220.89.252.50). The developer edition can only... -
I'm getting the following exception thrown
The underlying connection was closed: The server unexpectedly refused to keep the connection alive. Which is interesting in that this exception... -
Serialize complex type element with simple content
Hi, This must be easy, but I can't find an example: I want to automatically serialize an element with an attribute like the following... -
[HTML::Element] how to read element by element
Hello I read the doc about HTML::Element, but I don't find how to read the tree create by parse() element by element. The doc says the tree looks...



Reply With Quote

