I have a xml file that looks like this
<a>
<bb>
<c date="20110706" time="1:20" name1="john" name2="jen" nick1="johnny" nick2="jenny" />
<c date="20110806" time="2:20" name1="steven" name2="judith" nick1="steve" nick2="judy" />
</bb>
</a>
I currently have it set to grab the attributes value and set them as strings based on the value of one attribute. using this code
try {
String name1 = mName1;
XPath xpath = XPathFactory.newInstance().newXPath();
String expr = String.format("//a/bb/c[@* = '%s']", name1);
Node c = null;
try {
c = (Node) xpath.evaluate(expr, xml, XPathConstants.NODE);
} catch (XPathExpressionException e) {
e.printStackTrace();
}
What I am trying to accomplish is have all c lines listed one after the other in the format below using textviews, notice I do not want the nick1 and nick2 included. I have been reading and testing for hours with arraylist and cant get the result I am looking for. This is how I want all of the c nodes in the xml to be listed each in a textview.
Date:20110706 – Time:1:20 – HisName:john – HerName: jen
Date:20110806 – Time:2:20 – HisName:steven – HerName: judith
Also would would it be possible to have an imageview next to each name per line?
Thank you in advance for any help you can provide, I have been trying to do this for hours with no luck its driving me crazy!
EDIT: by doing just “//a/bb/c” I get the first line of the xml with the information I want, but how do I move on to the next line, and so on?
Specify a
returnTypeofXPathConstants.NODESETas the second argument toevaluateand iterate the results:I’ve shown the output for the
dateattribute only, but the others should be obvious from this example.