This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes XML document create with Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "XML document create with Java" Watch "XML document create with Java" New topic
Author

XML document create with Java

Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
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

Joined: Feb 23, 2009
Posts: 1183
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.


JDBCSupport - An easy to use, light-weight JDBC framework -
Ulas Ergin
Ranch Hand

Joined: Oct 10, 2002
Posts: 77
see NanoXML,it is a very simple to ise DOM parser.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

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:



Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
Thank You very much guys for your valuable ideas..im kind of researching on it these days with what you guys said
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML document create with Java