Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to do Xml in Java

Is there is Simple way to read and write Xml in Java?

I've used a SAX parser before but I remember it being unintuitive, I've looked at a couple of tutorials for JAXB and it just looks complicated.

I don't know if I've been spoilt by C#'s XmlDocument class, but All I want to do is create an Xml Document that represents a a set of classes and their members (some are attributes some are elements).

I would look into serialization but the XML has to have the same format as the output of a c# app which I am reverse engineering into Java.

like image 342
Omar Kooheji Avatar asked Feb 09 '09 15:02

Omar Kooheji


People also ask

How do you code XML in Java?

We must have followed the process to read an XML file in Java: Instantiate XML file: DOM parser loads the XML file into memory and consider every tag as an element. Get root node: Document class provides the getDocumentElement() method to get the root node and the element of the XML file.

Can we use XML in Java?

XML provides a universal syntax for Java semantics (behavior). Simply put, this means that a developer can create descriptions for different types of data to make the data behave in various ways with Java programming code, and can later repeatedly use and modify those descriptions.


1 Answers

I recommend XOM. Its API is clear and intuitive.

like image 63
grayger Avatar answered Sep 20 '22 22:09

grayger