I need to segregate xml code into two separate files by using the optional attribute values. I prefer to use the XML::LibXML DOM methods, using Perl.
Sample XML code excerpt:
...
<LocalJMS>
<Name>ZLAT</Name>
<PrimaryConnection>
<Address string="ops">ops.zla</Address>
<Address string="spt">spt.zla</Address>
<Port>77777</Port>
</PrimaryConnection>
<SecondaryConnection string="ops">
<Address>abc.zla</Address>
<Port>77777</Port>
</SecondaryConnection>
</LocalJMS>
The desirable resulting two final xml files would be:
1.) OPS file:
...
<LocalJMS>
<Name>ZLAT</Name>
<PrimaryConnection>
<Address>ops.zla</Address>
<Port>77777</Port>
</PrimaryConnection>
<SecondaryConnection>
<Address>abc.zla</Address>
<Port>77777</Port>
</SecondaryConnection>
</LocalJMS>
2.) SPT file:
...
<LocalJMS>
<Name>ZLAT</Name>
<PrimaryConnection>
<Address>spt.zla</Address>
<Port>77777</Port>
</PrimaryConnection>
</LocalJMS>
I have no problem/issue removing the attributes prior to generating the two final xml files, nor do I have any issue with making a decision on a element with an attribute that has no child elements - I can handle that as far pumping the xml content to the correct final xml file when I walk the DOM tree and checking on the childnodes.
But the problem I'm encountering is when the attribute is defined within a child element (e.g. 'SecondaryConnection', which is a child of 'LocalJMS'). If I "walk" the DOM tree, I will first encounter the parent element 'LocalJMS', and I need some of it's children elements (e.g. 'Name', 'PrimaryConnection') to go to both final files, but then I only need the 'SecondaryConnection' element to go only to the OPS xml file (not the SPT file). [btw, the attribute is applicable to all child nodes, i.e. 'Address' & 'Port']
I'm looking for some ideas - maybe using parse_balanced_chunk or work from the deepest part of the originally xml file and work outwards, cycling thru each child node. I hate like heck to have to use traditional grep patterns etc and treat the xml file like a simple text file - I was hoping to take advantage of the DOM methods.