Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML document create with Java

 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Can some one tell me how to create a XML document like following in java (in php it looks like following)



To be more specific im try to build this google map app using java http://code.google.com/apis/maps/articles/phpsqlsearch.html

Thank You.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SAXParser is a good XML parser for java. The sematics of xml parsers don't differ too much, it comes down to navigating through the DOM tree.
 
Ulas Ergin
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see NanoXML,it is a very simple to ise DOM parser.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like Harshana is looking for a way to generate an XML document - not for parsing an XML document.

You could use the XML stream API for that (see the package javax.xml.stream, new in Java 6), or you can just do it the simple way by printing the content out:

 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not great though. It doesn't handle escaping very well. I'd recommend a third party as well - JDOM.

Alternatively, you can use the Java SE API:
Output:
With thanks to Core Java Volume II
 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You very much guys for your valuable ideas..im kind of researching on it these days with what you guys said
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic