0

I need help in constructing XML dynamically. I have a XSD associated with the XML. Thing is my xml contains repititive elements/block. Sometimes it might contain 3 elements or sometime only one. Sample xml is below

<?xml version="1.0" encoding="utf-8"?>
<addml>
  <objectStore>
 <folder>
  <folderProperties>
    <documentId>str1234</documentId>
    <documentTitle>str1234</documentTitle>
    <dateCreated>str1234</dateCreated>
  </folderProperties>
  <documents>
    <document>
      <docProperties>
        <documentId>str1234</documentId>
        <documentTitle>str1234</documentTitle>
        <dateCreated>str1234</dateCreated>
      </docProperties>
    </document>
    <document>
      <docProperties>
        <documentId>str1234</documentId>
        <documentTitle>str1234</documentTitle>
        <dateCreated>str1234</dateCreated>
      </docProperties>
    </document>
  </documents>
</folder>
   </objectStore>
</addml>

As you can see above document tag can appear many times. all the values I will be getting from variables like (String documentID = "1234"). I need help in how to loop the elements and construct the above xml in java. Any help is much appreciated.

Thanks, Mark

user1194310
  • 129
  • 1
  • 4
  • 14
  • I have created a xml using JAXB. But the xml i have used is static in the sense I have assigned the constant values to the xml elements. But in this case it should be dynamic. That is where I am lost.. – user1194310 Oct 28 '15 at 19:18

1 Answers1

0

use DOM parser. consider

http://www.mkyong.com/java/how-to-create-xml-file-in-java-dom/

and

Xml file generator in java

Community
  • 1
  • 1
AbtPst
  • 7,778
  • 17
  • 91
  • 172