以下是XML-1:
<bookstore>
<book category="children">
<title>Harry Potter</title>
<author>J K. Rowling</author>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
</book>
</bookstore>如何通过添加两个元素<year>和<price>来创建基于XML-1的XML-2?它不复制XML-1,而是通过引用或包含它。这种分离对于将XML-1和XML-2分开存储是必要的,而不是在XML-2中复制XML-1中的信息。
为了最终能够创建XML-3:
<bookstore>
<book category="children">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>-2模式应该是什么样的?,我无法理解如何使用引用和包含。在这种情况下,我需要使用它们吗?还是需要其他的东西?
发布于 2018-03-25 16:34:50
您可以使用xsd扩展功能:https://www.liquid-technologies.com/xml-schema-tutorial/xsd-extending-types
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bookstore">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="title"/>
<xs:element type="xs:string" name="author"/>
</xs:sequence>
<xs:attribute type="xs:string" name="category" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>您需要创建一本扩展的书:
<xs:complexType name="ExtendedBook">
<xs:complexContent>
<xs:extension base="book">
<xs:sequence>
<xs:element type="xs:short" name="year"/>
<xs:element type="xs:float" name="price"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>https://stackoverflow.com/questions/49478044
复制相似问题