how do i merge the child elements in different XML files to a single XML

Hi,

I have an immediate requirement like below:

The following input XML files which are located in source dir(example:c:\source)

input1.xml

<?xml version="1.0" encoding="UTF-8"?>

<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="employee.xsd">

<emp id="100">

<property name="ARTIST">LATA MANGESHKAR</property>

<name>raj</name>

</emp>

<emp id="101">

<property name="ARTIST">KAMAL</property>

<name>kamaj</name>

</emp>

<emp id="102">

<property name="ARTIST">PANDI</property>

<name>kuma</name>

</emp>

<name ID="10"/>

</employee>

input2.xml

<?xml version="1.0" encoding="UTF-8"?>

<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="employee.xsd">

<emp id="200">

<property name="ARTIST">Raja</property>

<name>rajes</name>

</emp>

<emp id="201">

<property name="ARTIST">Guru</property>

<name>kaajal</name>

</emp>

<emp id="202">

<property name="ARTIST">Mani</property>

<name>selvan</name>

</emp>

<name ID="10"/>

</employee>

My output.xml should look like below:

<?xml version="1.0" encoding="UTF-8"?>

<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="employee.xsd">

<emp id="100">

<property name="ARTIST">LATA MANGESHKAR</property>

<name>raj</name>

</emp>

<emp id="101">

<property name="ARTIST">KAMAL</property>

<name>kamaj</name>

</emp>

<emp id="102">

<property name="ARTIST">PANDI</property>

<name>kuma</name>

</emp>

<emp id="200">

<property name="ARTIST">Raja</property>

<name>rajes</name>

</emp>

<emp id="201">

<property name="ARTIST">Guru</property>

<name>kaajal</name>

</emp>

<emp id="202">

<property name="ARTIST">Mani</property>

<name>selvan</name>

</emp>

</employee>

The above output.xml is generated based on the child element <NAME> of <employee> root element.

i will have to import only the package import org.jdom.*;

using jdom APIs like Element, Attribute , setAttribute, etc.. i will have to build the output.xml file.

......

Document xmlDoc = new Document(employee);

XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());

.....

Could you people post the sample code to generate the output.xml file which contains the merging of <emp> elements based on the unique id of <name ID="10"/>

Waiting for your valuable code!!

thanks

[3247 byte] By [Pannara] at [2007-11-26 13:16:10]
# 1
> Could you people post the sample codeNo. This isn't a site where people do your work for you. But if you tell us what you have done so far and what problems you are encountering, you will most likely get some help with those problems.
DrClapa at 2007-7-7 17:37:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...