将多个属性添加到架构中的多个元素(add multiple attributes to multiple elements in schema)
我无法弄清楚如何将多个节点的属性添加到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/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节点的属性声明。
I can't figure out how to add attributes for multiple nodes into an xsd file. This is my XML File.
<?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>Here is what I have so far. I can't get anything to work though.
<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>I also tried a global to add the attribute type but i can't get it to work. When i use the type it says i can't have any other complex or simple types along with the attribute declaration for the xmlnode Node.
最满意答案
我发现这似乎有效。 这是我之前搞砸的顺序。根
<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>I have found that this seems to work. It was the ordering that I messed up on earlier.Root
<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>更多推荐
发布评论