Cra*_*aig 6 java xml schema xsd jaxb
我正在处理 XML 模式,我想将生成的类中的字段名称从“值”更改为“名称”。我希望我的 StackOverflow.xsd 文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:StackOverflow="http://stackoverflow.com"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
targetNamespace="http://stackoverflow.com"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
jaxb:version="2.1">
<element name="toolbar">
<complexType>
<sequence>
<element name="action" type="StackOverflow:action" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute type="string" name="id" use="required"/>
</complexType>
</element>
<simpleType name="actionName">
<restriction base="string">
<enumeration value="Start"/>
<enumeration value="Stop"/>
<enumeration value="Cancel"/>
</restriction>
</simpleType>
<complexType name="action">
<simpleContent>
<extension base="StackOverflow:actionName">
<annotation>
<appinfo>
<!--This ensures that the field in the Action class will be called 'name' rather than 'value'-->
<jaxb:property name="name"/>
</appinfo>
</annotation>
<attribute name="isActive" type="boolean" default="false"/>
</extension>
</simpleContent>
</complexType>
</schema>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我尝试添加 jaxb:property 将字段“值”的名称更改为“名称”,但 XJC 抱怨“未使用指定的属性自定义”。这是我运行的命令
$ xjc StackOverflow.xsd -d tmp/
parsing a schema...
[ERROR] Specified property customization is not used.
line 33 of file:/D:/dev/workspace-action-engine/jris/jris/branches/action-engine/client/com.agfa.ris.client.lta/src/main/resources/com/agfa/ris/client/lta/listarea/controller/actionsmodel/StackOverflow.xsd
Failed to parse a schema.
Run Code Online (Sandbox Code Playgroud)
如果我从 XSD 文件中删除此部分:
<annotation>
<appinfo>
<!--This ensures that the field in the Action class will be called 'name' rather than 'value'-->
<jaxb:property name="name"/>
</appinfo>
</annotation>
Run Code Online (Sandbox Code Playgroud)
,那么这就是创建的Action.java文件
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2015.05.20 at 09:05:26 AM CEST
//
package com.stackoverflow;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
/**
* <p>Java class for action complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="action">
* <simpleContent>
* <extension base="<http://stackoverflow.com>actionName">
* <attribute name="isActive" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
* </extension>
* </simpleContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "action", propOrder = {
"value"
})
public class Action {
@XmlValue
protected ActionName value;
@XmlAttribute(name = "isActive")
protected Boolean isActive;
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link ActionName }
*
*/
public ActionName getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link ActionName }
*
*/
public void setValue(ActionName value) {
this.value = value;
}
/**
* Gets the value of the isActive property.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public boolean isIsActive() {
if (isActive == null) {
return false;
} else {
return isActive;
}
}
/**
* Sets the value of the isActive property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setIsActive(Boolean value) {
this.isActive = value;
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,@XmlValue 字段称为“value”,但我更希望将其称为“name”或“actionName”,但我不知道如何做到这一点。如果有人能提供任何帮助,我将不胜感激。
谢谢