1
我正在嘗試檢索父節點和子節點的屬性。我試圖用 showed here的例子,但它給我「不能應用於給定類型」。XML子節點屬性
static class Entry {
final String ED,Home, Shift, Detail;
Entry(String ED,String Home, String Shift,String Detail) {
this.ED= ED;
this.Home = Home;
this.Shift = Shift;
this.Detail = Detail;
Node entryNode = entriesNodeList.item(i);
entries.add(new Entry(
evalString(entryNode, "Home/@name"),
evalString(entryNode, "Home/@starDate"),
evalString(entryNode, "Home/@endDate"),
evalString(entryNode, "Home/Shift/@employeeID"),
evalString(entryNode, "Home/Shift/@start"),
evalString(entryNode, "Home/Shift/@end"),
evalString(entryNode, "Home/Shift/Detail/@start"),
evalString(entryNode, "Home/Shift/Detail/@end")
XML文件:
`<ED CS="BLUE" Timestamp="2011-03-23 13:57:01" xmlns:js="TEST/js">
<Home name="57511" startDate="2011-03-12" endDate="2011-03-18">
<Shift ID="1170108" start="2011-03-12 0718" end="2011-03-12 1636" >
<Detail type="Meal" start="2011-03-12 1218" end="2011-03-12 1248" />
</Shift>
</ED>`
帕特里克 - 這是有道理的,當我評論了評估字符串部分的四個額外的行我得到一個結果。我會按照你的建議研究複雜的類。 – Alex 2011-04-28 19:56:48
我更新了consractor和「Entry」類以接受8個字段。現在它返回所有8個預期值。但它只返回一行(該文件有幾行)。該行只返回一行。 for(Entry entry:entries){System.out.println(entry); } – Alex 2011-04-28 21:09:07