【问题标题】:XSD Namespace Not Appearing in JAXB Marshalled XMLXSD 命名空间未出现在 JAXB 编组 XML 中
【发布时间】:2014-02-07 17:10:43
【问题描述】:

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

当前马歇尔结果:

<exampleType>

期望的 Marshall 结果:

<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>

....

【问题讨论】:

    标签: java xml jaxb xsd


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多