0

I have a Perl object containing one scalar and two arrays of hashes.

I am using XML::Simple to save an XML copy of this data structure, but when I try to read in the XML file using XMLin I am getting a different data structure.

Is there any way to specify the structure in XMLin to take the format of the object I used to create the original XML file?

1 Answer 1

0

It sounds like you're creating XML just for the purposes of storing the data in your object?

If so you should look at something like FreezeThaw or Storable instead, which is meant for this purpose and will recreate and bless the object properly.

Depending on the data, even JSON might help you, but XML::Simple isn't very good at doing what it's intended for never mind about serializing arbitrary data structures.

5
  • I am actually trying to accomplish a few things. First I am trying to parse a text file into my data structure then output this data structure to xml format which I can do successfully. After that I am trying to read in the exact same xml file into my data structure so I can do more processing based on event driven feedback and output the new xml file with the additional tags that were originally blank filled in. I am then going to take this new xml file and apply an xslt script to it for further processing. Commented Jun 14, 2013 at 13:29
  • Then is the data structure open for change? I mean, would a proper DOM representation of the XML be acceptable? That is the only way you are going to get reproducible XML.
    – Borodin
    Commented Jun 14, 2013 at 15:32
  • Avoid Storable.
    – daxim
    Commented Jun 14, 2013 at 16:41
  • The xml should be in proper DOM representation. Commented Jun 14, 2013 at 21:04
  • @user2479059: I mean the internal representation. Can the form of the object be changed?
    – Borodin
    Commented Jun 15, 2013 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.