File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes How to create Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to create "two dimensional" XML structure (with repeated elements )using JDOM?" Watch "How to create "two dimensional" XML structure (with repeated elements )using JDOM?" New topic
Author

How to create "two dimensional" XML structure (with repeated elements )using JDOM?

Veljko Cankovic
Greenhorn

Joined: Dec 27, 2011
Posts: 12
Hi until now I always worked on example with this or similar structure:

<soapenv:Body>
<ns1:RebootDevice>
<ns1:data>
<ns1:attribute1>VALUE1</ns1:attribute1>
<ns1:attribute2>VALUE2</ns1:attribute2>
</ns1:data>
</ns1:RebootDevice>
</soapenv:Body>

And for that I always succesfully created that XML structure using JDOM on this way:



And that worked great!!

But now I have to create "two dimensional" xml structure -where some elements have repeated names and I do not know how

<soapenv:Body>
<ns1:RebootDevice>
<ns1:data>
<ns1:attribute1>VALUE1</ns1:attribute1>

<ns1:description>

<ns1:item>
<ns1:value>VALUE2<ns1:value>
<ns1:characteristic>attribute2<ns1:value>
</ns1:item>
<ns1:item>
<ns1:value>VALUE3<ns1:value>
<ns1:characteristic>attribute3<ns1:value>
</ns1:item>

</ns1:description>

</ns1:data>
</ns1:RebootDevice>
</soapenv:Body>

Could someone please help me based on my example how to create this strcuture where I have elements ITEM,VALUE,CHARACTERISTIC more than once??
Thank you
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

It doesn't matter if you create two, or two thousand, elements which have the same name. That's a perfectly normal thing to do. Try this slight modification of your existing code:

Veljko Cankovic
Greenhorn

Joined: Dec 27, 2011
Posts: 12
Paul Clapham wrote:It doesn't matter if you create two, or two thousand, elements which have the same name. That's a perfectly normal thing to do. Try this slight modification of your existing code:



It does matter becaue I am createing this in some java class and I MUST have same name for the elementse ITEM,VALUE AND CHARACTERSTIC!!! I simply must have two elements of ITEM,VALUE,CHARATCERSTIC but with different values for VALUE AND CHARACTERISTIC.

I think only solution is to put it in some array right? Do you please know solution? I can not create element attribute1again.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

Ah, now perhaps I understand. I thought your problem was how to create the Element objects. Which of course is not a problem at all, as my example shows. But it seems that your problem is actually that you need to design a data structure to store your data in before you produce your XML.

Or do I still not understand?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create "two dimensional" XML structure (with repeated elements )using JDOM?