好吧,我现在有一点冲突,我想执行一个XPath查询,但我没有到达解决这个问题.
这是我使用的XML文件的一个例子:
<?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 + ")"); } }}
其余的例子在这里:http://jexp.ru/index.php/Java_Tutorial/XML/XPath
总结以上是内存溢出为你收集整理的在Android中使用XPath在XML文件中搜索全部内容,希望文章能够帮你解决在Android中使用XPath在XML文件中搜索所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)