Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  XML Reader Classes  (Read 11386 times)
0 Members and 1 Guest are viewing this topic.
Offline CopyableCougar4

Senior Member


Medals: 8
Exp: 1 year



« Posted 2014-07-10 00:37:19 »

Hi

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
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

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #1 - Posted 2014-07-10 01:08:18 »

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

Offline CopyableCougar4

Senior Member


Medals: 8
Exp: 1 year



« Reply #2 - Posted 2014-07-10 01:09:17 »

Hi

Nope Smiley I prefer to do it myself where I can Smiley

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #3 - Posted 2014-07-10 03:23:38 »

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!

Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #4 - Posted 2014-07-12 18:04:18 »

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.

Offline PandaMoniumHUN

JGO Coder


Medals: 31
Exp: 3 years


White-bearded OGL wizard


« Reply #5 - Posted 2014-07-12 20:46:07 »

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? Huh

My Blog | Jumpbutton Studio - INOP Programmer
Can't stress enough: Don't start game development until you haven't got the basics of programming down! Pointing
Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Reply #6 - Posted 2014-07-27 23:44:22 »

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
 


Offline Slyth2727
« Reply #7 - Posted 2014-07-28 00:06:35 »

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!

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

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline gouessej
« Reply #8 - Posted 2014-07-28 08:34:31 »

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:
https://jaxb.java.net/tutorial/section_1_3-Hello-World.html#Hello%20World

Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #9 - Posted 2014-07-28 20:54:11 »

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? Huh
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.

Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (23 views)
2014-09-12 09:08:26

Norakomi (56 views)
2014-09-10 13:57:51

TehJavaDev (69 views)
2014-09-10 06:39:09

Tekkerue (34 views)
2014-09-09 02:24:56

mitcheeb (56 views)
2014-09-08 06:06:29

BurntPizza (40 views)
2014-09-07 01:13:42

Longarmx (25 views)
2014-09-07 01:12:14

Longarmx (31 views)
2014-09-07 01:11:22

Longarmx (31 views)
2014-09-07 01:10:19

mitcheeb (38 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!