0

我有以下架构元素,我想向它添加一个属性。

<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>
4

1 回答 1

0

this should do the trick:

<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>

you might wish to specify a different type for the attribute code.

于 2013-04-22T13:43:57.803 回答