将xjc生成的Java字段名从';价值';至';名称';
我正在处理一个XML模式,我想将生成的类中字段的名称从“value”更改为“name”。下面是我希望StackOverflow.xsd文件的外观:将xjc生成的Java字段名从';价值';至';名称';,java,xml,xsd,jaxb,schema,Java,Xml,Xsd,Jaxb,Schema,我正在处理一个XML模式,我想将生成的类中字段的名称从“value”更改为“name”。下面是我希望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
<?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>
如果我从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>
//重新编译源架构时,对此文件的任何修改都将丢失。
//生成日期:2015.05.20 CEST上午09:05:26
//
包com.stackoverflow;
导入javax.xml.bind.annotation.XmlAccessType;
导入javax.xml.bind.annotation.XmlAccessorType;
导入javax.xml.bind.annotation.XmlAttribute;
导入javax.xml.bind.annotation.XmlType;
导入javax.xml.bind.annotation.XmlValue;
/**
*操作复杂类型的Java类。
*
*以下架构片段指定此类中包含的预期内容。
*
*
*complexType name=“action”>
*simpleContent>
*扩展基=”http://stackoverflow.com>actionName“>
*属性名称=“isActive”类型=”{http://www.w3.org/2001/XMLSchema}布尔值“default=”false“/>
*/分机>
*/simpleContent>
*/complexType>
*
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=“action”,proporter={
“价值”
})
公共集体诉讼{
@XmlValue
受保护的ActionName值;
@xmltattribute(name=“isActive”)
受保护的布尔值是活动的;
/**
*获取value属性的值。
*
*@返回
*可能的对象是
*{@link ActionName}
*
*/
public ActionName getValue(){
返回值;
}
/**
*设置值属性的值。
*
*@param值
*允许的对象是
*{@link ActionName}
*
*/
public void setValue(ActionName值){
这个值=值;
}
/**
*获取isActive属性的值。
*
*@返回
*可能的对象是
*{@link Boolean}
*
*/
公共布尔值isIsActive(){
如果(isActive==null){
返回false;
}否则{
回报是积极的;
}
}
/**
*设置isActive属性的值。
*
*@param值
*允许的对象是
*{@link Boolean}
*
*/
public void setIsActive(布尔值){
this.isActive=值;
}
}
正如您所看到的,@XmlValue字段被称为“value”,但我更希望它被称为“name”或“actionName”,但我不知道如何做到这一点。如果有人能提供帮助,我将不胜感激
谢谢你得到过答案吗?我也一样。哦,不,我不记得了,那是5年前的事了。如果我以后有机会,我会看看我为修复它而编写的代码。
<annotation>
<appinfo>
<!--This ensures that the field in the Action class will be called 'name' rather than 'value'-->
<jaxb:property name="name"/>
</appinfo>
</annotation>
//
// 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;
}
}