gpt4 book ai didi

java - 生成具有模式中不存在的属性的 XML

转载 作者:行者123 更新时间:2023-11-29 09:11:31 27 4
gpt4 key购买 nike

我正在使用 JAXB 生成 OpenOffice XML,并且需要应用 xml:space="preserve"属性为 t元素。

    <r>
<t>
foo
</t>
</r>

应该是

    <r>
<t xml:space="preserve">
foo
</t>
</r>

我使用 JAXB 从 Open Office 模式生成 Java 类。 <t> type 在 CTRElt Java 类中表示为 String,因此无法设置此属性。当我从现有文档解码并编码时,以前存在 space属性不再存在。

架构的相关部分如下:

<xsd:element name="t" type="ST_Xstring" minOccurs="1" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>Text</xsd:documentation>
</xsd:annotation>
</xsd:element>

<xsd:simpleType name="ST_Xstring">
<xsd:annotation>
<xsd:documentation>Escaped String</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string" />
</xsd:simpleType>

如何生成具有此要求的 XML space属性?修改模式不是一种选择。我需要自定义 JAXB 吗?

最佳答案

我最终生成了 XML 并使用正则表达式添加了属性 :(

关于java - 生成具有模式中不存在的属性的 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12100764/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com