Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 25798
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Marshal
Posts: 25798
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic