簡體   English   中英

XMLBeans bounded Atom,設置入口內容

[英]XMLBeans bounded Atom, setting content of entry

這是一個與此類似的問題: xmlbeans - set content of a complex type但不完全相同。 我想要做的是在 atom 提要中設置 contentEntry 的內容。

這是 contentType 的 atom xsd 定義,即在 atom 提要中輸入的內容標簽。

<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 for atom,但我缺少一種能夠設置curContent的實際文本表示的方法。 只有其他的 set 函數是 set(XmlObject object) 和 setNil()。

我怎樣才能改變它,以便我可以得到:

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

謝謝

您需要進入 XmlCursor 區域才能插入混合內容。 例如,

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

    XmlCursor cur = null;
    try
    {
        cur = content.newCursor();
        cur.toFirstContentToken();
        cur.insertChars("Hello World");
    }
    finally
    {
        cur.dispose();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM