我一直试图在网上找出这个解决方案。我找到了解析XML文件的最有效方法。
以下是我的XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<game>
<person>
<name>ABC</name>
<address>XYZ</address>
<age>35</age>
</person>
<place>
<country>US</country>
<state>California</state>
<city>Fremont</city>
</place>
<thing>
<name>Book</name>
<use>Read and write</use>
</thing>
</game>
我必须使用Java中的 xPath 解析此XML文件。我希望将/*[i]
作为 xPath 表达式,其中i
是一个整数和0<i<4
。另外我想展示XML的整个“块”。那是
如果i = 1,则表达式必须返回<country>US</country><state>California</state><city>Fremont</city>
。请帮我解决这个问题。请不要在解决方案的任何步骤中使用DOM(例如Node类)。另外,请尝试使用Apache Commons框架,因为它在内部使用SAX Parser。
感谢。
答案 0 :(得分:0)