java - how to read the xml node value dynamically? -


i've static xml this. kind of configuration.

<scocodes>     <element scocode="c1" foo="fooc1" bar="barc1" />     <element scocode="c2" foo="fooc2" bar="barc2" />         <!-- these 100 nodes present --> </scocodes> 

for given scocode, want know foo value , bar value?

since static, need parse once in static block , convert kind of dto , put dtos in collection(list, set etc) elements(dtos) can searched?

try this

string xmlsource = "your xml"; string xpathexpression = "//element[@scocode='c1']/@foo | //element[@scocode='c1']/@bar";  xpath xpath = xpathfactory.newinstance().newxpath(); stringreader reportconfigurationxml = new stringreader(xmlsource); inputsource inputsource = new inputsource(reportconfigurationxml);  string result = (string) xpath.evaluate(xpathexpression, inputsource, xpathconstants.string); 

cheers, borut


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -