XSD を作成しましたが、要素の属性の 1 つに という名前が付けられていvalue
ます。私は JAXB を使用してクラスを作成しましたが、これらのクラスを使用して XML を作成した場合、XMLvalue
は属性ではなく、要素タグ内の値です。
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified" targetNamespace="http://ibm.org/seleniumframework"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Test" type="sel:Test" xmlns:sel="http://ibm.org/seleniumframework"/>
<xs:complexType name="Test">
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element type="sel:CLISessionType" name="CLISession" xmlns:sel="http://ibm.org/seleniumframework"/>
<xs:element type="sel:DBSessionType" name="DBSession" xmlns:sel="http://ibm.org/seleniumframework"/>
<xs:element type="sel:ScreensType" name="Screens" xmlns:sel="http://ibm.org/seleniumframework"/>
</xs:choice>
</xs:complexType>
<!--Screen XML section -->
<xs:complexType name="ScreensType">
<xs:sequence>
<xs:element type="sel:ScreenType" name="Screen" minOccurs="1" maxOccurs="unbounded" xmlns:sel="http://ibm.org/seleniumframework"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ScreenType">
<xs:sequence>
<xs:element type="sel:ScreenDataType" name="ScreenData" minOccurs="1" maxOccurs="unbounded" xmlns:sel="http://ibm.org/seleniumframework"/>
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="required" />
<xs:attribute type="xs:string" name="package" use="required" />
<xs:attribute type="xs:string" name="class" use="required" />
</xs:complexType>
<xs:complexType name="ScreenDataType">
<xs:sequence>
<xs:element type="sel:elementType" name="element"
minOccurs="1" maxOccurs="unbounded" xmlns:sel="http://ibm.org/seleniumframework"/>
</xs:sequence>
<xs:attribute type="xs:int" name="step" use="required"/>
<xs:attribute type="xs:string" name="description" use="required"/>
</xs:complexType>
<xs:complexType name="elementType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name" use="required" />
<xs:attribute type="xs:string" name="type" use="required" />
<xs:attribute type="xs:string" name="value" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<!--CLI XML section -->
<xs:complexType name="CLISessionType">
<xs:sequence>
<xs:element type="sel:CliLoginType" name="login"
minOccurs="1" maxOccurs="1" xmlns:sel="http://ibm.org/seleniumframework"/>
<xs:element type="sel:CommandsType" name="Commands"
minOccurs="1" maxOccurs="1" xmlns:sel="http://ibm.org/seleniumframework"/>
</xs:sequence>
<xs:attribute type="xs:string" name="use_test.properties"
use="required" />
</xs:complexType>
<xs:complexType name="CliLoginType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="host" use="required" />
<xs:attribute type="xs:string" name="password" use="required" />
<xs:attribute type="xs:string" name="username" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="CommandsType">
<xs:sequence>
<xs:element type="sel:CommandType" name="Command"
minOccurs="1" maxOccurs="unbounded" xmlns:sel="http://ibm.org/seleniumframework"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="CommandType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="exe" use="required"/>
<xs:attribute type="xs:string" name="args" use="required"/>
<xs:attribute type="xs:string" name="wait" use="required"/>
<xs:attribute type="xs:string" name="expectedOutput" use="required"/>
<xs:attribute type="xs:string" name="toVariable" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<!--DB XML section -->
<xs:complexType name="DBSessionType">
<xs:sequence>
<xs:element type="sel:DbLoginType" name="login" minOccurs="1"
maxOccurs="1" xmlns:sel="http://ibm.org/seleniumframework"/>
<xs:element type="sel:QueriesType" name="Queries"
minOccurs="1" maxOccurs="1" xmlns:sel="http://ibm.org/seleniumframework"/>
</xs:sequence>
<xs:attribute type="xs:string" name="use_test.properties"
use="required" />
<xs:attribute type="xs:string" name="use_dbserver" use="required"/>
<xs:attribute type="xs:string" name="use_db" use="required"/>
</xs:complexType>
<xs:complexType name="DbLoginType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="server" use="required"/>
<xs:attribute type="xs:string" name="database" use="required"/>
<xs:attribute type="xs:string" name="username" use="required"/>
<xs:attribute type="xs:string" name="password" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="QueriesType">
<xs:sequence>
<xs:element type="sel:SQLType" name="SQL" maxOccurs="unbounded"
minOccurs="1" xmlns:sel="http://ibm.org/seleniumframework"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="SQLType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="query" use="required"/>
<xs:attribute type="xs:string" name="expectedResults" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
バインディング ファイル:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<bindings schemaLocation="xmlSchema.xsd" version="1.0">
<!-- Customise the package name -->
<schemaBindings>
<package name="com.example.schema"/>
</schemaBindings>
<!-- rename the value element -->
<bindings node=".//xs:attribute[@name='value']">
<property name="ValueAttribute"/>
</bindings>
</bindings>
</bindings>
JAXB コマンド:
xjc -b xmlSchema.xjb -d C:\Users\Alison\workspace\FTFXmlGenerator\src -p com.q1labs.qa.xmlgenerator.model.generatedxmlclasses xmlSchema.xsd
要素内の値が属性として扱われるようにこれを編集するにはどうすればよいですか?
編集:
package com.qa.xmlgenerator.model.generatedxmlclasses;
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 elementType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="elementType">
* <simpleContent>
* <extension base="<http://www.w3.org/2001/XMLSchema>string">
* <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="type" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="value" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* </extension>
* </simpleContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "elementType", propOrder = {
"value"
})
public class ElementType {
@XmlValue
protected String value;
@XmlAttribute(name = "name", required = true)
protected String name;
@XmlAttribute(name = "type", required = true)
protected String type;
@XmlAttribute(name = "value", required = true)
protected String valueAttribute;
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setValue(String value) {
this.value = value;
}
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the type property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getType() {
return type;
}
/**
* Sets the value of the type property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setType(String value) {
this.type = value;
}
/**
* Gets the value of the valueAttribute property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getValueAttribute() {
return valueAttribute;
}
/**
* Sets the value of the valueAttribute property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setValueAttribute(String value) {
this.valueAttribute = value;
}
}