Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (857)
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  
  [LibGdx] Trouble parsing XML?  (Read 4532 times)
0 Members and 1 Guest are viewing this topic.
Offline Stein102

Junior Devvie

Medals: 1

« Posted 2013-08-27 16:01:37 »

I have the following XML I need to parse in my LibGdx game

   <item id="1" name="sword">
      <description text="Just a regular sword."/>
      <wieldable slot="HAND"/>
      <weapon damage = "3"/>

and I get an error on this code, any ideas?
XmlReader reader = new XmlReader();
Element root = reader.parse(items/Items.xml);

The error message is:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error parsing XML on line 1 near: items/Items.xml
Offline StrideColossus
« Reply #1 - Posted 2013-08-27 16:14:05 »

I'm not a libGDX user but you can see from the javadoc that the parse() method has several overrides, it's trying to parse the filename rather than the actual file - presumably you need to use a FileHandle or load the XML document before you pass it to the parser.

(BTW I'm assuming the code should have quotes around the filename otherwise it wouldn't have compiled).

Offline SrFurias

Senior Newbie

« Reply #2 - Posted 2013-08-28 21:46:02 »

Try put "" in Element root = reader.parse(items/Items.xml);
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-08-29 02:10:30 »

You should try out JSON... Usually better suited for data and LibGDX includes a nice utility for it.

Offline StrideColossus
« Reply #4 - Posted 2013-08-29 08:27:45 »

Try put "" in Element root = reader.parse(items/Items.xml);

I noticed that the filename didn't have quotes, but presumably the code wouldn't have compiled at all, so I assume that was just a typo.
The problem is definitely that the OP is not loading the actual XML document, instead the call to parse() is attempting to parse the filename!
Offline Stein102

Junior Devvie

Medals: 1

« Reply #5 - Posted 2013-08-29 17:04:25 »

I figured it out, I was trying to use a FilePath, not a FileName. So what I did was used the parse(FileHandle) method instead and it worked perfectly.
Pages: [1]
  ignore  |  Print  

hadezbladez (1157 views)
2018-11-16 13:46:03

hadezbladez (522 views)
2018-11-16 13:41:33

hadezbladez (1185 views)
2018-11-16 13:35:35

hadezbladez (269 views)
2018-11-16 13:32:03

EgonOlsen (2565 views)
2018-06-10 19:43:48

EgonOlsen (2784 views)
2018-06-10 19:43:44

EgonOlsen (1563 views)
2018-06-10 19:43:20

DesertCoockie (2267 views)
2018-05-13 18:23:11

nelsongames (2119 views)
2018-04-24 18:15:36

nelsongames (2813 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 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‑
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!