Jibx - 如何使用值和属性解组/编组标签?

发布于 2024-10-02 08:09:04 字数 334 浏览 0 评论 0原文

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

对不起,伙计们,我不是故意偷懒的。好的,问题是:我有上面的 xml 块的 xml 结构,其中一些标签在标签表示法中同时具有值​​和属性(MyTag 的值为 12 并具有属性名称)。使用 Jibx 如何为这种情况创建绑定模式。显然,对于只有值的 xml 标签或没有标签值的属性来说是正常的,但是当你同时拥有这两个标签时,我不知道该怎么办。谢谢。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼角的笑意。 2024-10-09 08:09:04

在绑定中使用 元素两次。一次使用 attribute 一次,一次使用 text 样式。

例如 - 要将以下 StateData 类绑定到您想要的 XML...

public class StateData {
  String name;
  String value;
}

...使用下面的绑定:

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文