• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get java object and display in XML format

 
saket gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi


suppose we are storing all instance variable of class obj in HashMap using reflection

and then we are iterating from HashMap and storing in XML format

we are storing field type , field name and field value in hashmap and output like this
<?xml version="1.0" encoding="UTF-8"?>

<root class="One" label=VAR1/>

<int name="int_One" >10</int>

<String name="str_One" >One</String>

<float name="float_one" >1.2</float>

</root>


what can i use for output like this ......
currently i m using StringBuffer for storing and printing in this way by hardcode
like this

for (int counter = 0; counter <= xmlfieldnames.size(); counter++) {

if (xmlfieldnames.get("FieldName" + counter) != null) {

xmlStrBuffer.append("\n<" +

xmlfieldtype.get("FieldType" + counter) + " name=\"" +

xmlfieldnames.get("FieldName" + counter) + "\" >" +

xmlfieldvalue.get("FieldValue" + counter) + "</" +

xmlfieldtype.get("FieldType" + counter) + ">");

}





waiting for reply
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm use DOM4j to create XML document.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basiscally, you might consider using JAXP (come with J2SE) or Xerces (developed by Apache) to create XML documents.

And they provide APIs for you to convert it into a "printable" format.

Nick
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the Castor XML mapping tool
http://castor.exolab.org/xml-mapping.html#3.3-The-<map-to>-element
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic