如何添加属性到这个元素(模式)

问题描述:

我有下面的模式元素,我想给它添加一个属性。如何添加属性到这个元素(模式)

<xsd:ComplexType> 
    <xsd:sequence>  
     <xsd:element name="Product" maxOccurs="1" minOccurs="0" > 
     <xsd:simpleType> 
      <xsd:restriction base="xsd:string"> 
       <xsd:maxLength value="100" /> 
      </xsd:restriction> 
     </xsd:simpleType> 
     </xsd:element> 
    </xsd:sequence> 
</xsd:ComplexType> 

眼下生成的XML看起来像:

<Product>This is the Product Translation for 001</Product> 

我想生成的XML看起来像:

<Product code="001">This is the Product Translation for 001</Product> 

这应该做的伎俩:

<xsd:ComplexType> 
    <xsd:sequence>  
     <xsd:element name="Product" maxOccurs="1" minOccurs="0" > 
      <xsd:complexType> 
       <xsd:restriction base="xsd:string"> 
        <xsd:maxLength value="100" /> 
       </xsd:restriction> 
       <xsd:attribute name="code" type="xs:string" use="required"/> 
      </xsd:complexType> 
     </xsd:element> 
    </xsd:sequence> 
</xsd:ComplexType> 

您可能希望指定不同的类型对于属性code

+0

当我使用JAXB创建对象时,这需要我为name =“code”创建一个新对象。有没有办法避免这种情况? – user2170437 2013-04-22 13:47:17

+0

对不起,我不知道。 – collapsar 2013-04-22 14:15:20