File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beginner Java and XML questions

 
The Insane dEvIL
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peer Reynders
Bartender
Posts: 2939
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic