Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Writing a java program with Eclipse. How do I read and write to XML?
I am trying to write a program and instead of linking it to a database I wanted to use a xml file to read information from and write information to. The problem is that I have no idea on where to start or how to do it. I am familiar with Java but I would say I am at a beginner stage with it. the IDE I use is Eclipse. Any help or examples would be great.
Thanks.
6 Answers
- 1 decade agoFavorite Answer
Java contains several methods to access XML. The following is a short overview of the available methods. The methods I consider most useful will then get later demonstrated.
1: DOM (DOCUMENT OBJECT MODEL) - Access is done over object tree. So, i don't use DOM just learn for basic understanding.
2: SAX (Simple API for XML) - Sequential reading of XML files and you cannot use it to create XML documents. so you cannot write data to create an XML documents. Don't use SAX to do this job.
3: STAX (Streaming API for XML) - This is an API used for reading and writing data to XML documents. This is superior to DOM and SAX and it is introduced in Java 6.0 .
4: JAXB (Java Architecture for XML Binding) - JAXB is a Java standard that defines how Java objects are converted to/from XML (specified using a standard set of mappings. JAXB defines a programmer API for reading and writing Java objects to / from XML documents and a service provider which / from from XML documents allows the selection of the JAXB implementation
JAXB applies a lot of defaults thus making reading and writing of XML via Java very easy.
For more control over the programming and data you should use JAXB.
Reading and writing data to XML through DOM:-
-------------------------------------------------------------------
http://java.sun.com/j2ee/1.4/docs/tutorial-update2...
Reading DOM tree from XML:-
------------------------------------------
http://www.java-tips.org/java-se-tips/org.w3c.dom/...
Advanced SAX:-
----------------------
http://www.devarticles.com/c/a/Java/Advanced-SAX/
__________________________________________________________
For clear understanding of using DOM and SAX check these articles. They implemented same theme but one in SAX and one in DOM. This will serve as a good guide.
Parsing XML using SAX:-
-----------------------------------
http://developerspoint.wordpress.com/2008/06/23/pa...
Parsing XML using DOM:-
------------------------------------
http://developerspoint.wordpress.com/2008/05/31/pa...
__________________________________________________________
[ AFTER KNOWING HOW TO USE DOM AND SAX IN JAVA GO THROUGH ADVANCED METHODS LIKE STAX AND JBIX. HERE I PRESENT YOU A LINK WHERE COMPLETE DESCRIPTION GIVING YOU COMPLETE CONTROL OVER AN XML FILE ]
**********************************************************************************
http://www.vogella.de/articles/JavaXML/article.htm...
Hope this helps a lot and i present you will useful resources. First get clear understanding on XML then using DOM and SAX to parse the XML in JAVA.
- Charles RLv 41 decade ago
XML is like HTML in that all it is is a text file. Most browsers have a parser and can parse the XML directly, how ever that is not what you are looking for you need to look into one of several other technologies. One and probably the easiest is AJAX. AJAX uses javascript the XMLHttpRequest object the native way to do this but you may find it easier to use one of the many JavaScript libraries like YUI, Dojo, or Jquery. Using this method the results returned can be manipulated directly using DOM. The other thing you could do is parse it directly on server as you said earlier this is slightly harder but not much. Most languages have some sort of XML reader for SAX(simple API for XML) or XML parser which will allow you to read the file into variables. Many languages also support XSLT, a language design to style and translate XML. I know that Java does provide SAX support I do not know how much more is available.
- Anonymous1 decade ago
Well, there are already many existing technologies that would help you on how to do that. You could create your own XML Java parser, but why reinvent the wheel?
There is so much more than I would ever be able to outline here, so in the meantime please check out the Java books on this subject on the following site:
It may be worth your time to learn a little more about Java in general before you tackle XML.
But, for more on XML and other web languages, please visit:
Good luck! Feel free to email me. I know a lot of software and resource areas that can save several thousand dollars.
- 1 decade ago
JAXP DOM: http://developers.sun.com/sw/building/codesamples/...
It's probably your best bet being a beginner; it allows you to deal with XML as a tree structure in your code.
- How do you think about the answers? You can sign in to vote the answer.
- Anonymous1 decade ago
I'm not too familiar with it, but this book looks pretty useful!
http://www.cafeconleche.org/books/xmljava/chapters...
Eclipse is an IDE...
- 1 decade ago
Eclipse is not an IDE. Eclipse is a game engine developed by http://www.touchofdeathproductions.com/ An IDE for Java would be Netbeans. Http://www.netbeans.org/ Contact me via yahoo messenger for more information (Knightblade9126).