大佬教程收集整理的这篇文章主要介绍了在Android中使用XPath在XML文件中搜索,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
好吧,我现在有一点冲突,我想执行一个XPath查询,但我没有到达解决这个问题.
<?xml version="1.0"?> <catalog> <book id="bk101"> <author>Gambardella,Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creaTing applications with XMl.</description> </book> <book id="bk102"> <author>Ralls,Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description>A former architect battles corporate zombies,an evil sorceress.</description> </book> <book id="bk103"> <author>Corets,Eva</author> <title>Maeve Ascendant</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-11-17</publish_date> <description>After the collapse of a nanotechnology society in England.</description> </book> </catalog>
我能怎么做??
提前致谢!!
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; public class GuestList { public static void main(String[] args) throws Exception { XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); NodeList shows = (NodeList) xPath.evaluate("/schedule/show",new Inputsource(new FileReader( "tds.xml")),XPathConstants.NODESET); for (int i = 0; i < shows.getLength(); i++) { Element show = (Element) shows.item(i); String guestName = xPath.evaluate("guest/name",show); String guestCredit = xPath.evaluate("guest/credit",show); System.out.println(show.getAttribute("weekday") + "," + show.getAttribute("date") + " - " + guestName + " (" + guestCredit + ")"); } } }
以上是大佬教程为你收集整理的在Android中使用XPath在XML文件中搜索全部内容,希望文章能够帮你解决在Android中使用XPath在XML文件中搜索所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。