wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Beginner Java and XML questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Beginner Java and XML questions" Watch "Beginner Java and XML questions" New topic
Author

Beginner Java and XML questions

The Insane dEvIL
Greenhorn

Joined: May 02, 2005
Posts: 5
I'm an absolute beginner with Java and XML. I know XML fairly well. I would really appreciate it if someone could point me to a tutorial or a book that explains how to read and generate XML files using Java.


Long Live The dEvIL
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Why not Sun's tutorial on XML and Java?

You will never be allowed to continue on the Ranch with an obviously fake name. Go fix it.

Bill
Edward Morris
Greenhorn

Joined: Jun 29, 2006
Posts: 18
Whats the big deal with the names here?

Besides, I need something even simpler and easier, if there is any...
[ June 29, 2006: Message edited by: Edward Morris ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by Edward Morris:
Whats the big deal with the names here?


See here and here for some background. We do take this rule (as well as the "Be Nice" rule) quite seriously.

Now, as far as your questions go: as you know, XML is just plain text. The very simplest way to create it is like this:

System.out.println("<?xml version='1.0'?>");
System.out.println("<body></body>");

Can't get much easier than that!

Now, for more helpful APIs, the tutorial mentioned above is going to be the best source. I can help you focus by pointing out the parts you really want to see. This document tells you how to build a DOM (document object model) using API calls, and then this page tells you how to turn a DOM into an XML file on disk.

Finally, here's the documentation page for the JDOM project; JDOM is similar to the standard DOM API, but simpler (and non-standard.) You pays your nickle and you makes your choice.


[Jess in Action][AskingGoodQuestions]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Edward Morris:
Besides, I need something even simpler and easier, if there is any�


I don't know about simpler � but at some point of time you may want to have a look at Elliotte Rusty Harold's Processing XML with Java.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
For ultra-simple, the O'Reilly XML Pocket Reference at 175 pages, is about the simplest you can get.
Harold's book is the best all-around reference I know of here is an online version. It is HUGE because the subject is huge.
Bill
Edward Morris
Greenhorn

Joined: Jun 29, 2006
Posts: 18
Thanks a lot guys, thats some good help I needed. I'm surprised JR doesn't have its own tut for this topic. Well to give you guys the big picture, I am working on this project

www.cs.bsu.edu/homepages/gnet/jedit.htm

Its a simple graph drawing s/w with some good graphs and algorithms.

Two things I wanna do with this are :

1. Incorporate XML output for the graphs and later graphml output.

2. Make this app runnable from the web, something like this

http://www.yworks.com/en/products_yed_about.htm


I'm a newbie with both of the above and I could really use some good and fast teaching help, and of course, I would really really appreciate it.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
If this was my problem I probably would start by thinking about how to represent the data points both as Java objects and as XML Elements.

In some projects where a Java object represents some sort of unit of data, I have given the class a toXML( Writer out ) method and a constructor that takes the corresponding XML Element.

There are lots and lots of toolkits for transforming XML to objects and back if you don't want to tackle the problem that way. Browse some of the recent discussions here for examples or do a search for "java xml serialization".

Bill
 
jQuery in Action, 2nd edition
 
subject: Beginner Java and XML questions
 
Similar Threads
How to connect to an UNIX server from Java application
abt xml
How to transform XSLT in java?
What do I need to start xml development?
Java and XML by Brett McLaughlin