JAXB - Annotations, Annotations for the Schema: XmlSchema

This annotation can only be used with a package. It defines parameters that are derived from the xsd:schema element. It must be written on a file package-info.java situated in the package. Below is an example, specifying the namespace and elementFormDefault elements.

@javax.xml.bind.annotation.XmlSchema(
namespace = "http://www.laune.at/hospital",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package hospital;

This annotation is equivalent to an xs:schema element

<xs:schema elementFormDefault="qualified"
targetNamespace="http://www.laune.at/hospital"
xmlns:tns="http://www.laune.at/hospital"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0" >

For defining namespace prefixes you use the xmlns element of the XmlSchema annotation. It contains an array of XmlNs annotations, each of which contains a prefix and anamespaceURI element. The previous example is extended with a namespace definition for the prefix med:

@javax.xml.bind.annotation.XmlSchema(
namespace = "http://www.laune.at/hospital",
xmlns = { @javax.xml.bind.annotation.XmlNs( prefix = "med",
namespaceURI = "http://www.laune.at/med" ) },
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package hospital;

This corresponds to using xmlns:med="http://www.laune.at/med" as an attribute in the xs:schema element.

上一篇:抽出SqlHelper


下一篇:一文搞懂 Java 线程中断