0

以下のような XML があり、XStream を使用してこの XML を解析します

<Annotation name="uniqueMembers">true</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;
}
}

このタグの値が「true」である必要がありますが、呼び出すときに

 xStream.fromXML("myXml.xml");

それはなぜnull値を持っていますか? このタグの「true」を取得するにはどうすればよいですか?

編集: 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>
4

2 に答える 2

0

次の XML スニペットを試してください。

<Annotation>
    < uniqueMembers>true< /uniqueMembers>
</Annotation>
于 2013-07-15T06:21:12.850 に答える
0

現時点で書かれているように、あなたがそこに示したクラスは次のようなものを期待しています

<Annotation name="something">
  <value>the value</value>
</Annotation>

<value>要素を削除して<Annotation>要素のコンテンツのみを使用するにはToAttributedValueConverter、を使用する必要があります。このブログ投稿には詳細が記載されていますが、基本的には追加する必要があります

@XStreamConverter(value=ToAttributedValueConverter.class, strings={"value"})

クラスのクラスレベルの注釈としてAnnotation

于 2013-07-15T07:51:56.267 に答える