Building an xml in java

55 pts.
Tags:
AS/400
Java
JDBC
SQL Query
XML
Please give me an example of building an xml with multiple child nodes, in java.

I want something like :

<Parent>

<Child1>something</Child1>

<Child2>something else</Child2>

</Parent>

Now, the values for Child1 and Child2 must be picked using SQL from AS400. Picking values is where i think i am failing. My program constructs something like :

<Parent>

<Child1>something</Child1>

</Parent>

<Parent>

<Child2>something else</Child2>

</Parent>

:( help!

 

 



Software/Hardware used:
java 1.5, as400, jdbc

Answer Wiki

Thanks. We'll let you know when a new response is added.

Try this:

http://www.lmgtfy.com/?q=example+of+building+an+xml+with+multiple+child+nodes+in+java

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • AshishSingh10
    Hi, 

    The below mentioned code might prove to be helpful: -

    protected void setNodeValue(String tagName, String value, NodeList nodes) {
        Node node = getNode(tagName, nodes);
        if ( node == null )
            return;
     
        // Locate the child text node and change its value
        NodeList childNodes = node.getChildNodes();
        for (int y = 0; y < childNodes.getLength(); y++ ) {
            Node data = childNodes.item(y);
            if ( data.getNodeType() == Node.TEXT_NODE ) {
                data.setNodeValue(value);
                return;
            }
        }


    Thanks and regards
    1,330 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: