gpt4 book ai didi

java - XSD 命名空间未出现在 JAXB 编码 XML 中

转载 作者:太空宇宙 更新时间:2023-11-04 07:04:19 25 4
gpt4 key购买 nike

当我从 JAXB 生成的 XSD/Schema 类编码 XML 时,根节点缺少 xmlns:xsi 信息,请参见下文。关于如何在我的编码 XML 中获取命名空间信息有什么想法吗?

当前编码(marshal)结果:

<exampleType>

期望的编码(marshal)结果:

<exampleType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../schemas/example.xsd"> 

我的架构(部分示例):

 <?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0.1">
<xs:element name="project" type="exampleType">
<xs:annotation>
<xs:documentation>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../schemas/example.xsd"
</xs:documentation>
</xs:annotation>

...

最佳答案

要使 xsi:noNamespaceSchemaLocation 架构位置属性出现在编码 XML 中,您需要使用 JAXB_NO_NAMESPACE_SCHEMA_LOCATION 属性在 Marshaller 上设置它。

marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "../schemas/example.xsd");

关于java - XSD 命名空间未出现在 JAXB 编码 XML 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21633797/

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