I need to create a StringArray with nametext from:
<xs:element name="xyz" type="xs:string/>
<xs:element name="bla" type="xs:string/>
...
How can I request "xyz", "bla" and many others?
Probably the worst code you've ever seen, but anyway:
NodeList result1 = (NodeList) xPath.evaluate("//@name", example, XPathConstants.NODESET); for(int i=0; i<result1.getLength();i++) { System.out.println("read 1:" +result1.item(i)); } //console output is: //read 1:name="xyz" //read 1:name="bla" ArrayList<String> liste; liste = new ArrayList<String>(result1.getLength()); for (int i=0; i<result1.getLength();i++){ String read=xPath.evaluate("//@name", example); liste.add(read); System.out.println("read 2: "+read); } System.out.println("complete list: " +liste); //console output is: //read 2:name="xyz" //read 2:name="xyz" //complete list: [xyz, xyz]
Thanks for the help, made it work as follows:
(just in case .. if anyone ever seeks a solution here)
NodeList result = (NodeList) xPath.evaluate("//@name", example, XPathConstants.NODESET); liste = new ArrayList<String>(result.getLength()); for(int i=0; i<result.getLength();i++){ liste.add(result.item(i).getNodeValue()); } return(liste);
source share