java - How to get Inner array child element in XML using ximpleware -
autopilot searchproperties = new autopilot(); searchproperties.selectxpath("/batchitemsearchresultanswer/result/searchproperties/content/item"); searchproperties.bind(nav); searchpro searchoption = new searchpro(); while (searchproperties.evalxpath() != -1) { //reuser name.resetxpath(); name.selectxpath("name"); searchoption.id = id.evalxpathtostring(); searchoption.name = name.evalxpathtostring(); log.e("searchid", id.evalxpathtostring()); log.e("searchname", name.evalxpathtostring()); image.resetxpath(); image.selectxpath("/batchitemsearchresultanswer/result/searchproperties/content/item/values/propertyvalue"); searchoption.propertylist = new arraylist(); while (image.evalxpath() != -1) { property pro = new property(); pro.id = id.evalxpathtostring(); log.e("searchpid", id.evalxpathtostring()); log.e("searchpname", name.evalxpathtostring()); searchoption.propertylist.add(pro); } }
here xml
<searchproperties><content> <item><id>12345</id><name>scene</name><values><propertyvalue><id>29</id><name>le</name></propertyvalue> <propertyvalue><id>208</id><name>business</name></propertyvalue> </values></item><item>..</item></content></searchproperties>
searchproperties while loop 1 time . when remove image.selectpath("") line. time loop correctly. how solve this.
thanks in advance.
you nesting xpath evaluations... better move xpath selection out of while loop whenever possible. reason compile xpath relatively speaking slow operation... needs construct xpath data structure, perform various optimization speeds xpath evaluation...
manual navigation might more efficient in use case have indicated want loop on xml tree once...
also nested 1 absolute xpath inside related absolute xpath, bad performance, , not make sense... changed image object's xpath binding relative xpath "values/propertyvalue
."
the overall goal reduced wasteful computation , maximize reuse. concerning xpath reuse, aware there 4 methods xpath evaluation... evalxpath()
, evalxpathtostring()
, evalxpathtoboolean()
, evalxpathtonumber()
. of 4 methods, evalxpath() requires resetxpath() subsequent reuse... other 3 call resetxpath internally..and not require call resetxpath() after each invocation.
autopilot searchproperties = new autopilot(); autopilot image = new autopilot(vn); autopilot name = new autopilot(vn); name.selectxpath("name"); image.selectxpath("values/propertyvalue");// should use relative path here, makes huge difference in performance searchproperties.selectxpath("/batchitemsearchresultanswer/result/searchproperties/content/item"); searchproperties.bind(nav); searchpro searchoption = new searchpro(); while (searchproperties.evalxpath() != -1) { //reuser //name.resetxpath(); searchoption.id = id.evalxpathtostring(); searchoption.name = name.evalxpathtostring(); log.e("searchid", id.evalxpathtostring()); log.e("searchname", name.evalxpathtostring()); searchoption.propertylist = new arraylist(); vn.push() while (image.evalxpath() != -1) { property pro = new property(); pro.id = id.evalxpathtostring(); log.e("searchpid", id.evalxpathtostring()); log.e("searchpname", name.evalxpathtostring()); searchoption.propertylist.add(pro); } image.resetxpath(); vn.pop(); }
Comments
Post a Comment