【问题标题】:XMLBeans bounded Atom, setting content of entryXMLBeans bounded Atom,设置入口内容
【发布时间】:2017-05-07 23:00:05
【问题描述】:

这是一个与此类似的问题: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"/>

我真的不想与 atom 的官方(我能找到的官方)xsd 混淆,但我缺少一种能够设置 curContent 的实际文本表示的方法。只有其他的 set 函数是 set(XmlObject object) 和 setNil()。

我怎样才能改变它以便我可以得到:

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

谢谢

【问题讨论】:

    标签: java xsd atom-feed xmlbeans


    【解决方案1】:

    您需要进入 XmlCursor 区域才能插入混合内容。例如,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      • 2014-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多