Xml 向架构中的多个元素添加多个属性
我不知道如何将多个节点的属性添加到xsd文件中。 这是我的XML文件Xml 向架构中的多个元素添加多个属性,xml,xsd,Xml,Xsd,我不知道如何将多个节点的属性添加到xsd文件中。 这是我的XML文件 <?xml version="1.0" encoding="utf-8"?> <xs:Root xmlns:xs="http://tempuri.org/SchemaFile" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tempuri.org/
<?xml version="1.0" encoding="utf-8"?>
<xs:Root xmlns:xs="http://tempuri.org/SchemaFile"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tempuri.org/SchemaFile SchemaFile.xsd"
xmlns:elementFormDefault="qualified">
<xs:Node name="attributeName">
<xs:data name="attributeName" amount="total" /> // These are unbounded.
</xs:Node>
</xs:Root>
//这些是无限的。
这是我到目前为止所拥有的。不过我什么都做不了
<sch:element name="Root">
<sch:complexType>
<sch:sequence>
<sch:element name="Node" maxOccurs="unbounded">
<sch:complexType>
<sch:simpleContent>
<sch:extension base="sch:string">
<sch:attribute name="name" type="sch:string"/>
</sch:extension>
</sch:simpleContent>
</sch:complexType>
</sch:element>
</sch:sequence>
</sch:complexType>
</sch:element>
我还尝试了全局添加属性类型,但无法使其工作。当我使用该类型时,它会说我不能有任何其他复杂或简单的类型以及xmlnode节点的属性声明。我发现这似乎是可行的。我之前搞砸的是订单。根
<sch:element name="Root">
<sch:complexType>
<sch:sequence>
<sch:element name="Node" maxOccurs="unbounded">
<sch:complexType>
<sch:sequence>
<sch:element name="Data" maxOccurs="unbounded">
<sch:complexType>
<sch:attribute name="name"/>
<sch:attribute name="amount"/>
</sch:complexType>
</sch:element>
</sch:sequence>
<sch:attribute name="name"/>
</sch:complexType>
</sch:element>
</sch:sequence>
</sch:complexType>
</sch:element>
试试这个:
<xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="Node" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="data" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="amount">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
它适用于以下XML:
<Root>
<Node>
<data name="string 1" amount="string 2"/>
<data name="string 3" amount="string 4"/>
</Node>
</Root>
也别忘了用上面的xsd验证这个xml文件,以便正确运行。请看我上面的问题,然后看我的帖子。我找到了解决办法。这对我没有帮助,因为这不是我要的。感谢您的尝试。请注意,xs
通常用作XML模式的名称空间前缀(http://www.w3.org/2001/XMLSchema
)当你把这个前缀用在别的东西上,而把另一个前缀用在http://www.w3.org/2001/XMLSchema
-我不得不读了两遍你的问题,才知道实例文档在顶部,架构在底部,而不是相反……实例文档不是问题所在。这是属性排序中的一个问题,因为我的两个节点都附加了属性。我认为属性必须首先列出,而实际上它们必须在其他元素之后列出。