Home: Perl Programming Help: Beginner:

New User

Dec 6, 2012, 12:11 PM

Views: 1729

Hi There,

I am trying to read in an XML file and check if a list ofcertain codes are contained in an element. If so I simply want to keep those records that match and discard the ones that do not match. In other words like searching for a key value on a table and only returning that set. So far I have managed to read the file and interogate the element. Then I try and write out the XML that I was reading and it seems to lose the tags of the outer elements. It is as if some of the inner elements become attributes of the outer eleemnts. I print Dumper and I can see the data. So I am wondering do I parse the data into a structure and then once I have found all the records I require write that out to an XML file? Or to a flate file? Been going up and down all day on the net and cannot seem to get the solution I need. Please help.

Thanks in Advance


Dec 7, 2012, 8:56 AM

Views: 1722
Re: [HenryL] XML::Simple

What you experience, is a consequence of XML::Simple. This is what "simple" means - simple to use, but sloppy. In particular, elements and attributes are often treated the same:

<A B="C"/>

Please read the docs - they describe this behaviour, and explain how to bypass them (there are several examples in the docs which likely will apply exactly to your problem).

If you find configuring XML::Simple too tedious, you could use one of the other XML modules. They are less "simple", but don't cause this type of confusion.