[英]don't read value of element in XML by xstream
i have an XML like below and i use XStream to parse this XML 我有如下所示的XML,并且我使用XStream解析此XML
<Annotation name="uniqueMembers">true</Annotation>
and a class for Annotation : 还有一个Annotation类:
@XStreamAlias("Annotation")
public class Annotation {
@XStreamAsAttribute
private String name;
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
i need value have "true" of this tag but when i call 我需要值具有此标签的“ true”,但是当我打电话时
xStream.fromXML("myXml.xml");
it have null value why? 它具有空值为什么? how can i get "true" of this tag? 我如何获得此标签的“真”?
EDIT : part of MyXml.xml 编辑:MyXml.xml的一部分
<Dimension name="Branch" >
<Hierarchy name="xxx" primaryKey="" hasAll="true" allMemberName="All" >
<Table schema="vvv" name="ccc" />
<Level name="State" captionColumn="STATE_NAME" uniqueMembers="true" type="Integer" />
<Level name="City" captionColumn="CITY_NAME" uniqueMembers="true" type="Integer">
<Annotations>
<Annotation name="uniqueMembers">true</Annotation>
</Annotations>
</Level>
<Level name="Branch" captionColumn="BRANCH_NAME" uniqueMembers="true" type="Integer" >
<Annotations>
<Annotation name="uniqueMembers">true</Annotation>
</Annotations>
</Level>
</Hierarchy>
</Dimension>
Try this XML snippet: 尝试以下XML代码段:
<Annotation>
< uniqueMembers>true< /uniqueMembers>
</Annotation>
As written at the moment, the class you've shown there expects something like 如目前所写,您在此处显示的课程期望
<Annotation name="something">
<value>the value</value>
</Annotation>
To get rid of the <value>
element and just use the <Annotation>
element's content, you need to use a ToAttributedValueConverter
, this blog post has the details but essentially you need to add 要摆脱<value>
元素而只使用<Annotation>
元素的内容,您需要使用ToAttributedValueConverter
, 此博客文章中有详细信息,但实际上您需要添加
@XStreamConverter(value=ToAttributedValueConverter.class, strings={"value"})
as a class-level annotation on your Annotation
class. 作为Annotation
类的类级注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.