[英]Jibx - how to unmarshal/marshal tag with value and attribute?
<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). 好的问题是:我的xml结构带有上面的xml块,其中一些标签在标记符号中具有值和属性(MyTag的值为12且具有属性名称)。 using Jibx how I can create binding schema for such case. 使用Jibx如何为这种情况创建绑定模式。 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. 显然,对于只有值的xml标签或没有标签值的属性是正常的,但是当你同时拥有它们时我不知道该怎么做。 Thanks. 谢谢。
Use <value/>
element twice in your binding. 在绑定中使用<value/>
元素两次。 Once with attribute
and once with text
styles. 一次使用attribute
,一次使用text
样式。
For example - to bind the following StateData
class to the XML you want... 例如 - 将以下StateData
类绑定到您想要的XML ...
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.