java - Cannot parse value from xml to code libgdx -
i trying parse data xml file libgdx game. xml file looks this:
<?xml version="1.0" encoding="utf-8"?> <levels currentlevel = "1"> <level1 speed="1" direction="1" lineangle="14" /> <level2 speed="1" direction="1" lineangle="14" /> <level3 speed="1" direction="1" lineangle="14" /> </levels>
and code call in show method take values xml is:
xmlreader xml = new xmlreader(); try { xmlreader.element element = xml.parse(gdx.files.internal("levels.xml")); xmlreader.element root = element.getchildbyname("levels"); currentlevel = root.getint("currentlevel"); xmlreader.element level = root.getchildbyname("level1"); lineangle = level.getint("lineangle"); speed = level.getfloat("speed"); direction = level.getint("direction"); }catch (exception e){}
but cannot value xml. example, expect lineangle 14 0. can explain me why this? , solution great. thanks.
when parse file element @ root of xml. works me:
xmlreader xml = new xmlreader(); try { // element root element of document, i.e. <levels> xmlreader.element element = xml.parse(gdx.files.internal("d:\\somefolder\\android\\assets\\levels.xml")); currentlevel = element.getint("currentlevel"); xmlreader.element level = element.getchildbyname("level1"); lineangle = level.getint("lineangle"); speed = level.getfloat("speed"); direction = level.getint("direction"); } catch (exception e) { }
i had give complete path levels.xml, e.g.: "d:\somefolder\android\assets\levels.xml"
Comments
Post a Comment