Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, I could use some advice, this is my dilema: I have several strings of data that I will split and populate an array with. After I populate the array, I need to pop the items off to build an xml script. My problem is that some of the strings contain the same data (ie:Topology and IPClassA)
Topology/IPClassA = 1/Device = 1/Port = 1 Topology/IPClassA = 1/Device = 2/Port = 2 Topology/IPClassB = 3/Device = 3
The number of times Topology is displayed is important but irrelevant in my example, my main concern is every element after that, so my objective is to somehow parse the data and end up with the following:
<Topology> <IPClassA = 1> <Device = 1> <Port = 1> </Port = 1> </Device = 1> <Device = 2> <Port = 2> </Port = 2> </Device = 2> </IPCLASSA = 1> <IPCLASSB = 3> <Device = 3> <?Device = 3> </IPCLASSB = 3> </Topology>
Any suggestions? Thanks

Replies are listed 'Best First'.
Re: Data Structure Advice
by seattlejohn (Deacon) on Mar 07, 2002 at 03:29 UTC
    A couple of thoughts. First off, you said you want to generate XML, but you should be aware that the example you give is pretty far from being legal XML. XML is case-sensitive; values must be associated with attributes, not the base tags; and attribute values must be contained in quotes. In other words, your XML should probably look more like this:
    <IPClassA id = "1"> <Device id = "1"> </Device> </IPClassA>
    (Actually, for empty elements you can combine the opening and closing tags as in <Device id = "1" />, but that's not particularly important here.)

    Anyway, the comments in this node may point you in the right direction.