如何让JAXB编组字符串或原始数据类型并在生成的XML中设置type =“string”或type =“int”。我尝试为每个字段指定特定类型
@XmlSchemaType(name = "string",namespace = "http://www.w3.org/2001/XMLSchema",type = String.class)
但是这没有区别,结果XML没有类型。
感谢您阅读
的更新 的 这基本上就是我在JaxB类中所拥有的:
@XmlElement(required = true)
protected Keys keys;
protected String workflowID;
protected String fromFigure;
protected String fromPort;
这是生成的XML
<keys type="draw2d.ArrayList">
<data type="Array">
<element type="draw2d.FlowConnectionModel">
<workflowID>d8f71b92-dc69-4115-9095-d748265d4e68</workflowID>
<fromFigure>706531d9-cd03-4347-9ba2-d9b525035e0d</fromFigure>
<fromPort>out_right_initialState</fromPort>
请注意,键,数据和元素类型有一个类型集,但对于workflowID,fromFigure和fromPort的原始数据类型没有。我想要的是这个:
<keys type="draw2d.ArrayList">
<data type="Array">
<element type="draw2d.FlowConnectionModel">
<workflowID type="string">d8f71b92-dc69-4115-9095-d748265d4e68</workflowID>
<fromFigure type="string">706531d9-cd03-4347-9ba2-d9b525035e0d</fromFigure>
<fromPort type="string">out_right_initialState</fromPort>
答案 0 :(得分:1)
您不会看到生成的XML有任何区别。如果您从班级生成XSD,则需要看到XSD的差异。
答案 1 :(得分:0)
最后,我必须更改模式以使用复杂类型而不是简单类型。 来自原始架构的片段
<xs:element name="layoutWorkflowID" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="layoutInstanceID" type="xs:string" minOccurs="1" maxOccurs="1"/>
已更改为
<xs:element ref="layoutWorkflowID" minOccurs="1" maxOccurs="1"/>
<xs:element ref="layoutInstanceID" minOccurs="1" maxOccurs="1"/>
使用额外的复杂类型
<xs:element name="layoutWorkflowID">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:NCName">
<xs:attribute name="type" use="required" type="xs:NCName"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
现在,当我使用指定的每种类型进行编组时,我得到了我需要的东西。
<layoutWorkflowID type="string">WorkflowHTML</layoutWorkflowID>
<layoutInstanceID type="string">6</layoutInstanceID>
感谢那些回复和阅读的人。