Recently I started using XML more and now I'm stuck on a weird problem that I can't find a solution to anywhere. How do you read an attribute from a characters event in? I'll show you the XML code and a snippet of the Java code below.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<entity id="Player">
<state>MainMenu</state>
<attr id="health">10</attr>
<attr id="inventory">axe</attr>
<controller>0</controller>
</entity>
</config>
Java:
if (event.asStartElement().getName().getLocalPart().equals("attr"))
{
event = eventReader.nextEvent();
System.out.println("Attr: " + event.asCharacters().toString());
System.out.println();
// Iterator<Attribute> attributes = event.asStartElement().getAttributes();
/*while (attributes.hasNext())
{
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("id"))
{
e.addAttribute(attribute.getValue(), event.asCharacters().getData());
}
}*/
continue;
}