@Retention(value=RUNTIME) @Target(value=PACKAGE) public @interface XmlSchema
将包名称映射到XML命名空间。
XmlSchema注释可以与以下程序元素一起使用:
这是一个包级注释,并遵循JSR 175第三部分“注释”中的建议和限制。 因此,使用受到以下限制和建议的约束。
示例1:自定义包映射到的XML命名空间的名称。
  @javax.xml.bind.annotation.XmlSchema (
      namespace = "http://www.example.com/MYPO1"
    )
    <!-- XML Schema fragment -->
    <schema
      xmlns=...
      xmlns:po=....
      targetNamespace="http://www.example.com/MYPO1"
    >
    <!-- prefixes generated by default are implementation
            depedenent -->  
       示例2:自定义命名空间前缀,命名空间URI映射
  // Package level annotation
    @javax.xml.bind.annotation.XmlSchema (
      xmlns = {
        @javax.xml.bind.annotation.XmlNs(prefix = "po",
                   namespaceURI="http://www.example.com/myPO1"),
        @javax.xml.bind.annotation.XmlNs(prefix="xs",
                   namespaceURI="http://www.w3.org/2001/XMLSchema")
      )
    )
    <!-- XML Schema fragment -->
    <schema
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:po="http://www.example.com/PO1"
        targetNamespace="http://www.example.com/PO1">  
       示例3:自定义elementFormDefault
  @javax.xml.bind.annotation.XmlSchema (
      elementFormDefault=XmlNsForm.UNQUALIFIED
      ...
    )
    <!-- XML Schema fragment -->
    <schema
        xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:po="http://www.example.com/PO1"
        elementFormDefault="unqualified">  
      | Modifier and Type | Fields and Description | 
|---|---|
| static String | NO_LOCATIONlocation()属性的默认值,表示模式生成器将在此命名空间中生成组件。 | 
| Modifier and Type | Optional Element and Description | 
|---|---|
| XmlNsForm | attributeFormDefault
              属性的命名空间资格。 
             | 
| XmlNsForm | elementFormDefault
              元素的命名空间资格。 
             | 
| String | location
              表示此命名空间(由 
              namespace()指定 )具有在该位置可用的模式已经可用。 | 
| String | namespace
              XML命名空间的名称。 
             | 
| XmlNs[] | xmlns
              自定义命名空间URI,前缀关联。 
             | 
public static final String NO_LOCATION
location()属性的默认值,表示模式生成器将在此命名空间中生成组件。 
          public abstract XmlNs[] xmlns
public abstract String namespace
public abstract XmlNsForm elementFormDefault
public abstract XmlNsForm attributeFormDefault
public abstract String location
namespace()指定 )具有在该位置可用的模式。 
           这指示JAXB模式生成器简单地引用指向的模式,而不是将组件生成到模式中。 假设该模式与模式生成器将生成的模式相同(相同的元素名称,相同的类型名称...)
当一组Java类最初是从现有模式生成的,手工编写为匹配外部定义的模式,或者手动修改生成的模式时,将使用此功能。
值可以是任何绝对URI,如http://example.org/some.xsd 。 也可以指定空字符串,以指示模式是外部可用的,但位置未指定(因此生成模式的读者有责任定位它)最后,此属性的默认值"##generate"表示模式生成器将为此命名空间生成组件(如在JAXB 2.0中所做的那样)。
 允许多个包上的多个XmlSchema注释管理相同的namespace() 。 在这种情况下,所有这些都必须具有相同的location()值。 
更确切地说,值必须是"","##generate",或a valid lexical representation of xs:anyURI与<scheme>:开始。
模式生成器预计将生成一个对应的<xs:import namespace="..." schemaLocation="..."/> (或者如果指定了空字符串,则完全没有schemaLocation属性)。但是,允许模式生成器在schemaLocation属性(包括不生成此属性)中使用不同的值,示例,以便用户可以通过命令行界面指定资源的本地副本。
 Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.