我正在尝试为此xml获取有效的xsd架构。一些元素属于默认命名空间,而b属于命名空间。它远非完整,但我坚持room
的定义。它显示了这个错误:
Warning 1 The element 'rooms' in namespace 'building' has invalid child element 'room'. List of possible elements expected: 'room' in namespace 'building'.
如何在正确的命名空间中定义房间类型?
的xml:
<?xml version="1.0"?>
<b:building xmlns:b="building">
<b:rooms>
<room>101</room>
<room>102</room>
<room>201</room>
</b:rooms>
<b:occupations>
<occupation datum="2012-06-30">
<room nummer="101">Comment</room>
<room nummer="102"/>
</occupation>
<occupation datum="2012-07-01">
<room nummer="101"/>
<room nummer="201">Comment 2</room>
</occupation>
</b:occupations>
</b:building>
XSD:
<?xml version="1.0"?>
<xsd:schema targetNamespace="building"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="building"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="building">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="rooms">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="room" type="room" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="occupations">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="occupation" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="room">
</xsd:complexType>
</xsd:schema >
答案 0 :(得分:0)
XML文档中的元素空间和职业没有前缀。由于范围中也没有默认命名空间,因此在XML Schema术语中,它们被认为是不合格的,因为它们不属于构建命名空间。
在您的架构中,您需要添加form =&#34;不合格&#34;在适用的每个要素中这样说。
<?xml version="1.0"?>
<xsd:schema targetNamespace="building"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="building"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="building">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="rooms">
<xsd:complexType>
<xsd:sequence>
<xsd:element form="unqualified" name="room" type="xsd:integer" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="occupations">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="occupation" form="unqualified" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema >
上面的模式在房间元素声明上还有两个编辑:maxOccurs和整数类型。
我已根据上述架构成功检查了您的文档的有效性。
另一种解决方案是在原始文档中的房间和占用前添加b:前缀。然后你可以删除form =&#34;不合格&#34;来自架构。