0

これは、これに似た質問です:xmlbeans-複合型のコンテンツを設定しますが、まったく同じではありません。私がやろうとしているのは、AtomフィードのcontentEntryのコンテンツを設定することです。

これは、contentTypeのアトムxsd定義、つまりアトムフィードにエントリするためのコンテンツタグです。

<xs:complexType name="contentType" mixed="true">
    <xs:annotation>
        <xs:documentation>
            The Atom content construct is defined in section 4.1.3 of the format spec.
        </xs:documentation>
    </xs:annotation>
    <xs:sequence>
        <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="type" type="xs:string"/>
    <xs:attribute name="src" type="xs:anyURI"/>
    <xs:attributeGroup ref="atom:commonAttributes"/>
</xs:complexType>

xmlbeanのscompでコンパイルした後、次のことができるようにする素敵なjarファイルを取得します。

EntryType curEntry;
curEntry = atomFeed.addNewEntry();
ContentType curContent = curEntry.addNewContent();
curContent.setBase("base");
curContent.setLang("en-EN");
curContent.setSrc("none");
curContent.setType("none");

そしてこれはとして出力されます

<content xml:base="base" xml:lang="en-EN" src="none" type="none"/>

アトムの公式(私が見つけた限り公式)のxsdをいじりたくないのですが、curContentの実際のテキスト表現を設定できるメソッドがありません。他の集合関数のみがset(XmlObjectオブジェクト)とsetNil()です。

取得できるようにこれを変更するにはどうすればよいですか:

<content xml:base="base" xml:lang="en-EN" src="none" type="none">Content of this entry</content>

ありがとう

4

1 に答える 1

0

混合コンテンツを挿入するには、XmlCursor ランドにドロップする必要があります。例えば、

    ContentType content = x.addNewContent();
    content.setType("none");

    XmlCursor cur = null;
    try
    {
        cur = content.newCursor();
        cur.toFirstContentToken();
        cur.insertChars("Hello World");
    }
    finally
    {
        cur.dispose();
    }
于 2011-07-21T21:02:09.127 に答える