[LibGdx] Trouble parsing XML?

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

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

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

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.

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/XmlReader.html

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

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

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

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!

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.