questions on XML::Simple

J

Jeff

I used the XML::Simple module to read some xml, which works great.

But when I write it back out with XMLout.. it's changed.

For example the input that looks like this:

<Summary>
<TotalOrders>1</TotalOrders>
<TotalLineItems>4</TotalLineItems>
<TotalQuantity>158</TotalQuantity>
</Summary>

ends up looking like this:

<Summary TotalLineItems="4" TotalOrders="1" TotalQuantity="158" />


Is it possible to have it written out in the same format it was read
from? Is there another module that would do this?

Thanks.
 
B

Ben Morrow

Quoth Jeff said:
I used the XML::Simple module to read some xml, which works great.

But when I write it back out with XMLout.. it's changed.

For example the input that looks like this:

<Summary>
<TotalOrders>1</TotalOrders>
<TotalLineItems>4</TotalLineItems>
<TotalQuantity>158</TotalQuantity>
</Summary>

ends up looking like this:

<Summary TotalLineItems="4" TotalOrders="1" TotalQuantity="158" />


Is it possible to have it written out in the same format it was read
from?

See the NoAttr option.
Is there another module that would do this?

There are lots of other XML modules (XML::parser, XML::LibXML, the
XML::SAX modules, XML::DOM, ...) but if XML::Simple does what you need
it's probably better to stick with what you have. If your XML really is
always going to be as simple as you say you could try XML::Tiny, but
make sure you carefully read the list of what it does and doesn't
support.

Ben
 
X

xhoster

Ben Morrow said:
See the NoAttr option.

Use ForceArray when doing XMLin. I think this would be better than
using NoAttr on XMLout. With ForceArray things that were attributes on the
way in are still attributes on the way out, while tags on the way in are
tags on the way out--rather than turning everything into tags.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
P

Peter J. Holzer

No, because XML::Simple doesn't keep all the necessary information.

Use ForceArray when doing XMLin. I think this would be better than
using NoAttr on XMLout. With ForceArray things that were attributes on the
way in are still attributes on the way out, while tags on the way in are
tags on the way out--rather than turning everything into tags.

Agreed. But it will still not preserve the order of elements:

<Summary>
<TotalLineItems>4</TotalLineItems>
<TotalOrders>1</TotalOrders>
<TotalQuantity>158</TotalQuantity>
</Summary>

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top