SimpleXml经验总结

Q:inline参数是什么意思

 

 

A:对于如下结构的xml节点

 

XML语言: Codee#14196
<propertyList>
   <name> example </name>
   <entryList>
      <entry key= "one" >
       <value> first value </value>
      </entry>
      <entry key= "two" >
       <value> second value </value>
      </entry>
      <entry key= "three" >
       <value> third value </value>
      </entry>
   </entryList>
</propertyList>

 

entry节点其实是一个List,不过又没有用这种写法

 

XML语言: Codee#14195
<propertyList>
   <name> example </name>
   <entry key= "one" >
      <value> first value </value>
   </entry>
   <entry key= "two" >
      <value> second value </value>
   </entry>
   <entry key= "three" >
      <value> third value </value>
   </entry>
</propertyList>

 

 

所以在Java的类中对应的时候需要使用inline标签

 

Java语言: Codee#14202
@ElementList ( entry = "entry" , required = true , inline = true )
public List < entry > entryList ;

 

 

Q:entry参数是什么

 

A:当Java类中的节点名称和xml节点不相对应的时候,需要用entry指定xml文件中的节点名称

 

XML语言: Codee#14197
<root>
   <username> aaa </username>
   <password>bbb </password>
   <abc key= "Key0" value= "Value0" />
   <abc key= "Key1" value= "Value1" />
   <abc key= "Key2" value= "Value2" />
</root>

 

Java类中对应为

 

Java语言: Codee#14198
@Root( name = "root")
public class GlobalUserInfoConfig {

    @Element( required = true)
    public String username;

    @Element( required = true)
    public String password;

    @ElementList( entry = "abc" , required = true , inline = true)
    public List < GlobalParameter > globalConfigList;
   
}

 

 

 

你可能感兴趣的:(java,xml)