Search In Xml File With Xpath In Android
I'm developping an application on android! Well I have a little conflict now, I want to execute an XPath query but I didn't arrive to solve this problem. This an example of XML fi
Solution 1:
Look at this example:
import java.io.FileReader;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
publicclassGuestList {
publicstaticvoidmain(String[] args)throws Exception {
XPathFactoryfactory= XPathFactory.newInstance();
XPathxPath= factory.newXPath();
NodeListshows= (NodeList) xPath.evaluate("/schedule/show",
newInputSource(newFileReader("tds.xml")), XPathConstants.NODESET);
for (inti=0; i < shows.getLength(); i++) {
Elementshow= (Element) shows.item(i);
StringguestName= xPath.evaluate("guest/name", show);
StringguestCredit= xPath.evaluate("guest/credit", show);
System.out.println(show.getAttribute("weekday") + ", " + show.getAttribute("date") + " - "
+ guestName + " (" + guestCredit + ")");
}
}
}
The rest of examples are here : http://jexp.ru/index.php/Java_Tutorial/XML/XPath
Post a Comment for "Search In Xml File With Xpath In Android"