XML Reader Classes

Hi

With this code you can extend ReadableXMLElement, and use it’s methods to parse an XML File. Here is an example implementation.


package me.CopyableCougar4.xml;

/**
 * This is just a wrapper for generic XML parsing
 * @author CopyableCougar4
 *
 */
public class XMLElementImplementation extends ReadableXMLElement {

	/**
	 * Construct the element.
	 * @param title
	 * 		File name
	 * @param tag
	 * 		Tag for each element that's read
	 * @param wrapper
	 * 		Wrapper element around tag instances
	 */
	public XMLElementImplementation(String title, String tag, String wrapper) {
		super(title, tag, wrapper);
	}

	@Override
	public void parseElement() {

	}

}

Pastebin: http://pastebin.java-gaming.org/a354c4d100b1b

Hope someone finds this helpful!

CopyableCougar4

Have you ever looked at http://simple.sourceforge.net/?

Hi

Nope :slight_smile: I prefer to do it myself where I can :slight_smile:

CopyableCougar4

No offense but… its kind of easier to just use someone else’s wrapper. There is no point in rolling your own. Its very much a newbie perspective on things, to do everything yourself. I’m not saying you shouldn’t, you really will learn a lot, but avoid rolling everything yourself whenever possible!

Yeah, don’t always just say I am going to roll it myself. If you are trying to get a project done in a certain amount of time then you should always try to find a library. If it is a hobby project that you are trying to learn things then go ahead. Even then sometimes you can get frustrated with a hobby project when you are trying to do everything yourself.

Generally I agree with the idea that you should only ever roll something yourself if learning is what matters to you and not productivity, but Java has 3 built-in ways of parsing XML (DOM, SAX, StAX) which are all really easy to use so why would anyone use a library for this? ???

JAXP (SAX and DOM) is a very old model for parser

the J2EE official parser now is JAXB and it is moved to JDK since version 1.6
no more need to write any rows of code to parse an XML

JAXB create beans that have a relation with the xml and load automaticaly the xml populating for you the bean
or can automatically serialize the bean in xml in case you need to save data

what you need is just an xsd that describre the xml, that is all

so you can also use a run time to save information in case

and it is standard Java

reference oracle documentation
http://www.oracle.com/technetwork/articles/javase/index-140168.html

Why not just use Unity then?
When you create something yourself, you learn loads more.

That’s what several people here expressed, creating something yourself even though there are already some libraries that do the same is interesting mostly for pedagogical purposes, the interest depends on where you are and where you want to go as I explained here.

Edit.: This is a simple example that uses JAXB:

Because you still have to do the marshaling yourself. With SimpleXML you create POJOs and then use a serializer to read/write your XML file. All the marshaling is done for you.