commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruben Silva <ruben.si...@saphety.net>
Subject [CONFIGURATION] addNodes()
Date Wed, 25 Jul 2007 11:43:05 GMT
Hi,

I'm trying to use the method XMLConfiguration.addNodes() to add a tree 
of configuration properties to a node in other tree, like this:
 
public static void main(String ...args){     
        try{
            configDestination = new XMLConfiguration("output.xml");
            configSource = new XMLConfiguration("input.xml");
        }
        catch(ConfigurationException cex){
            System.out.println("File not found");
        }
       
        Collection collection = new ArrayList();
        collection = configSource.getRoot().getChildren();
       
        configDestination.addNodes("newNodes", collection);     
       
        try {
            configDestination.save();
      
        } catch (ConfigurationException e) {
            System.out.println("Error saving");
            e.printStackTrace();
        }
}


The XML files:

input.xml

<rootNode>
    <newNodeChild>
        <newNodeChildChild>child value</newNodeChildChild>
        <newNodeChildChild>child value 2</newNodeChildChild>
        <newNodeChildChild>child value 3</newNodeChildChild>
    </newNodeChild>
</rootNode>

output.xml

<testRootNode>
    <test>TEST</test>
</testRootNode>

output.xml after running the code:

<testRootNode>
    <test>TEST</test>
    <newNodes/>
</testRootNode>

Expected output.xml:

<testRootNode>
    <test>TEST</test>
    <newNodes>
        <newNodeChild>
            <newNodeChildChild>child value</newNodeChildChild>
            <newNodeChildChild>child value 2</newNodeChildChild>
            <newNodeChildChild>child value 3</newNodeChildChild>
        </newNodeChild>
    <newNodes/>
</testRootNode>

Hope someone can help me.

-- 
Ruben Silva 

Research & Development – Saphety Level - Trusted Services SA
E-mail: ruben.silva@saphety.net



Mime
View raw message