开发者

Jibx - how to unmarshal/marshal tag with value and attribute?

开发者 https://www.devze.com 2023-01-25 01:31 出处:网络
<stateData> <MyTag name=\"voltage\">12</Mytag> <MyTag name=\"Fuel\">72</Mytag>
<stateData>
   <MyTag name="voltage">12</Mytag>
   <MyTag name="Fuel">72</Mytag>
</stateData>

Sorry Guys, I did not meant to be lazy. Ok Here is the question: I have xml structure with above block of xml which some tags has both value and attribute in tag notation( MyTag has value of 12 and has an attribute name). using Jibx how I can create binding schema for such case. Obviously for xml tags w开发者_Go百科ith only value or with attributes without tag value is normal, but when you have both of them I don't know what to do. Thanks.


Use <value/> element twice in your binding. Once with attribute and once with text styles.

For example - to bind the following StateData class to the XML you want...

public class StateData {
  String name;
  String value;
}

...use the binding below:

<binding>
  <mapping name="stateData" class="StateData">
    <structure name="MyTag">
      <value style="attribute" name="name" field="name"/>
      <value style="text" field="value"/>
    </structure>
  </mapping>
</binding>
0

精彩评论

暂无评论...
验证码 换一张
取 消