Hello All,

This for the first time I am interacting with a XML file through Perl. As a
matter of fact I am using any XML file the first time so I may go here &
there with the technical terms of the XML file. I apologize for that.

Following is the structure of my XML file

<root>
<start_element>
<element_num>1</element_num>
<child>MyChild</child>
</start_element>
<start_element>
<element_num>2</element_num>
<child>MyChild</child>
<user_id>MyUser</user_id>
</start_element>
<start_element>
<element_num>3</element_num>
<child>MyChild</child>
</start_element>
</root>

As you can see the xml file starts with the root element followed by many
elements having the tag – ‘start_element’. Some of the elements may have
child elements with the tag – user_id, as shown in the case of 2nd element.
The value of the child element <user_id> can be anything.

Now I want to split the original xml file into 2 xml files. First xml files
will contain all the elements having child element - <user_id>. The second
file will contain all the remaining elements. So for above example, I will
need to generate 2 files.

First xml file will contain following :
<root>

<start_element>
<element_num>2</element_num>
<child>MyChild</child>
<user_id>MyUser</user_id>
</start_element>
</root>

Second xml file will contain remaining 2 elements:
<root>
<start_element>
<element_num>1</element_num>
<child>MyChild</child>
</start_element>
<start_element>
<element_num>3</element_num>
<child>MyChild</child>
</start_element>
</root>

Currently I am planning to process the above requirement using simple Perl
regex. But I feel it can be made simpler using any of the available modules.

So I have following questions:
1.       Which are the best available XML modules for Perl?
2.       Out of the best available modules, which one would suite my
requirement in the best way?
3.       Any pointers to specific methods of the XML modules to suffice my
needs would be helpful.
TIA

Cheers,
Parag

Reply via email to