【问题标题】:Where does xmlns:tns come from when using schemagen使用 schemagen 时 xmlns:tns 来自哪里
【发布时间】:2012-11-14 17:32:21
【问题描述】:

我们正在使用 schemagen 从一些带注释的 POJO 创建 XSD。

这是我们的蚂蚁目标

<target name="generate-xsd" depends="compile">
    <taskdef name="schemagen" classname="com.sun.tools.jxc.SchemaGenTask" 
                     classpathref="xjc.classpath"/>
    <schemagen srcdir="src" destdir="generated" includeantruntime="false">
        <include name="com/acme/exam/delivery/records/**"/>
        <schema namespace="http://www.acme.com/deliverylog" 
                            file="deliverylog.xsd"/>
        <schema namespace="" file="supplemental.xsd"/> 
    </schemagen>
</target>

这是生成

<xs:schema elementFormDefault="qualified" version="1.0" 
           targetNamespace="http://www.acme.com/deliverylog" 
           xmlns:tns="http://www.acme.com/deliverylog" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema">

tns 命名空间从何而来,它意味着什么?

【问题讨论】:

    标签: xsd jaxb schemagen annotated-pojos


    【解决方案1】:

    该信息来自包级别注释@XmlSchema,可以在package-info 类中找到。请参阅下面的示例。

    包裹信息

    @XmlSchema(
        namespace = "http://www.acme.com/deliverylo",
        elementFormDefault = XmlNsForm.QUALIFIED)
    package example;
    
    import javax.xml.bind.annotation.XmlNsForm;
    import javax.xml.bind.annotation.XmlSchema;
    

    示例 XML

    elementFormDefault 指定哪些元素应该是命名空间限定的(true = 全部,false = 仅全局元素),targetNamespace 定义命名空间是什么。

    <foo xmlns="http://www.acme.com/deliverylog">
        <bar>Hello World</bar>
    </foo>
    

    更多信息

    【讨论】:

      猜你喜欢
      • 2016-07-09
      • 1970-01-01
      • 2010-09-21
      • 2014-04-24
      • 2015-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多