0
我有一個xml文件,我想讀取xml的所有子節點的值。我的xml是如何在java中使用xpathh讀取xml的所有節點?
<branches>
<branch-area name="abc">
<branch>
<branch-name> xyz Street</branch-name>
<branchID>5689742</branchID>
<branchAddress>xyz address</branchAddress>
<atm>true</atm>
<branch>true</branch>
<tab title="Contact">
<![CDATA[<table>
<tr>
<td class="head">Branch</td>
<td>bandra Street</td>
</tr>
<tr>
<td class="head">Address</td>
<td>bandra Street</td>
</tr>
<tr>
<td class="head">Sort Code</td>
<td>215863</td>
</tr>
</table>]]>
</tab>
</branch>
</branch-area>
<branch-area name="def 11">
<branch>
<branch-name>pqr</branch-name>
<branchID>123456</branchID>
<branchAddress>pqr address </branchAddress>
<atm>true</atm>
<branch>true</branch>
<tab title="Contact">
<![CDATA[<table>
<tr>
<td class="head">Branch</td>
<td>bandra Street</td>
</tr>
<tr>
<td class="head">Address</td>
<td>bandra Street</td>
</tr>
<tr>
<td class="head">Sort Code</td>
<td>215863</td>
</tr>
</table>]]>
</tab>
</branch>
</branch-area>
<branch-area name="ghi 14">
<branch>
<branch-name>jkl</branch-name>
<branchID>589674</branchID>
<branchAddress>jkl address</branchAddress>
<atm>true</atm>
<branch>true</branch>
<tab title="Contact">
<![CDATA[<table>
<tr>
<td class="head">Branch</td>
<td>bandra Street</td>
</tr>
<tr>
<td class="head">Address</td>
<td>bandra Street</td>
</tr>
<tr>
<td class="head">Sort Code</td>
<td>215863</td>
</tr>
</table>]]>
</tab>
</branch>
</branch-area>
</branches>
並且我正在使用此xpath expreesion獲取特定分支。
String xpathExpression = "/branches/branch-area[name='abc']/branch";
它返回我即
<branch>
<branch-name> xyz Street</branch-name>
<branchID>5689742</branchID>
<branchAddress>xyz address</branchAddress>
<atm>true</atm>
<branch>true</branch>
<tab title="Contact">
<![CDATA[<table>
<tr>
<td class="head">Branch</td>
<td>bandra Street</td>
</tr>
<tr>
<td class="head">Address</td>
<td>bandra Street</td>
</tr>
<tr>
<td class="head">Sort Code</td>
<td>215863</td>
</tr>
</table>]]>
</tab>
</branch>
特定的分支,但我想它的孩子像分支名稱branchID等方面的價值,做我需要使用另一個XPath表達式爲每子節點還是有另一種方式呢?如果是,請指導我
嗨,我只是更新我的xml,如果我想要一個表內的值我怎麼能得到它們? – user2142786 2014-10-31 07:37:29
你需要創建適當的路徑,但過程是一樣的 – MadProgrammer 2014-10-31 07:45:33
好的謝謝隊友:) – user2142786 2014-10-31 07:48:35