简体   繁体   中英

XML Child node attribute

I am trying to retrieve attributes for parent and child nodes. I tried to use the exampleshowed here but it is giving me "can't be applied to given type".

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 FILE:

`<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>`

The constructor for the class "Entry" only takes 4 String arguments and you are trying to call it with. The Class also only seems to hold 4 fields. Maybe you'd want to actually introduce complex Classes for ED (with the fields CS, Timestamp, Home and Shift), Home, Shift and Detail which would represent your xml file as a Java object hierarchy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM