0
最近我開始更多地使用XML,現在我陷入了一個奇怪的問題,我無法找到任何解決方案。你如何閱讀來自角色事件的屬性?我將向您展示XML代碼和下面的Java代碼片段。Java XML屬性
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;
}
看起來像http://stackoverflow.com/q/7435674/217324的副本? –