gpt4 book ai didi

xml - JAXB XJC 编译器忽略 XML 模式文档上的 mixed=true

转载 作者:数据小太阳 更新时间:2023-10-29 01:43:10 24 4
gpt4 key购买 nike

XJC 似乎完全忽略了我的 XML 模式元素上的 mixed="true",因此不允许我提取文本内容。从下面的示例 XML 中,我需要能够提取“标题文本”。如果不识别 mixed="true",则不会创建访问器,也不会从 XML 中解码:

<?xml version="1.0" encoding="UTF-8"?>
<title xmlns="urn:hl7-org:v3" integrityCheck="true">Title Text</title>

这是一个完整但最小化的模式来演示问题:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema targetNamespace="urn:hl7-org:v3"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="urn:hl7-org:v3"
xmlns:mif="urn:hl7-org:v3/mif"
elementFormDefault="qualified">

<xs:complexType name="ST" mixed="true">
<xs:complexContent>
<xs:restriction base="ED">
<xs:sequence>
<xs:element name="reference" type="xs:string" minOccurs="0" maxOccurs="0"/>
<xs:element name="thumbnail" type="xs:string" minOccurs="0" maxOccurs="0"/>
</xs:sequence>
<xs:attribute name="compression" type="xs:string" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="ED" mixed="true">
<xs:complexContent>
<xs:extension base="BIN">
<xs:sequence>
<xs:element name="reference" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="thumbnail" minOccurs="0" maxOccurs="1" type="xs:string" />
</xs:sequence>
<xs:attribute name="compression" type="xs:string" use="optional" />
<xs:attribute name="integrityCheck" type="xs:string" use="optional" />
<xs:attribute name="integrityCheckAlgorithm" type="xs:string" use="optional" default="SHA-1" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="BIN" abstract="true" mixed="true">
<xs:complexContent>
<xs:extension base="ANY">
<xs:attribute name="representation" use="optional" type="xs:string" default="TXT" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="ANY" abstract="true">
<xs:attribute name="nullFlavor" type="xs:string" use="optional" />
</xs:complexType>

<xs:element name="title" type="ST" />
</xs:schema>

请注意,在上面我有 mixed="true"。尽管如此,生成的架构片段不包含对它的引用,生成的类也不使用 XmlMixed 注释,也不包含值或内容访问器:

/**
* <p>Java class for ST complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="ST">
* <complexContent>
* <restriction base="{urn:hl7-org:v3}ED">
* <sequence>
* <element name="reference" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="0" minOccurs="0"/>
* <element name="thumbnail" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="0" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ST")
public class ST
extends ED
{
}

为什么 XJC/JAXB 完全无视我的混合内容字段?我已经尝试过 JAXB 2.1 和 JAXB 2.2,但生成的代码中只存在细微差别。

注意:我无法更改架构,因为实际架构是符合标准的医疗保健 (HL7) 架构。

最佳答案

http://blogs.oracle.com/mgrebac/entry/handling_extended_mixed_content_in

这成功了!只需像这样创建一个绑定(bind)文件:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
xmlns:xjc= "http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc">
<jaxb:globalBindings generateMixedExtensions="true"/>
</jaxb:bindings>

然后按照您通常的方式在命令行中使用-b参数。

关于xml - JAXB XJC 编译器忽略 XML 模式文档上的 mixed=true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4049067/

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