Jibx-如何使用值和属性解组标签? [英] Jibx - how to unmarshal/marshal tag with value and attribute?

查看:105
本文介绍了Jibx-如何使用值和属性解组标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<stateData>
   <MyTag name="voltage">12</Mytag>
   <MyTag name="Fuel">72</Mytag>
</stateData>

对不起,我不是要偷懒.好的,这里的问题是:我具有上面的xml块的xml结构,其中某些标签在标签符号中同时具有值​​和属性(MyTag的值为12并具有属性名称).使用Jibx,如何为这种情况创建绑定架构.显然,对于仅具有值的xml标记或具有不具有标记值的属性的xml标记是正常的,但是当您同时拥有它们时,我不知道该怎么做.谢谢.

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 with 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.

推荐答案

在绑定中两次使用<value/>元素.一次使用attribute样式,一次使用text样式.

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

例如-将以下StateData类绑定到所需的XML ...

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>

这篇关于Jibx-如何使用值和属性解组标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆