【发布时间】:2016-01-19 16:32:35
【问题描述】:
我正在针对输入 xml 创建一个架构,其中我的主要要求是使 ParcelNumber 或 WorkArea 强制,所以这是我的输入 xml
<?xml version="1.0" encoding="utf-8"?>
<NOCPlantMapRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<NOCTypeID>0</NOCTypeID>
<WorkLocation>
<ParcelNumber>4545</ParcelNumber>
<Roads>
<WorkLocationRoad>
<RoadName>chennai road</RoadName>
</WorkLocationRoad>
</Roads>
<WorkArea>
<WorkArea>
<Coordinates>
<WorkLocationCoordinate>
<CoordinateX>56</CoordinateX>
<CoordinateY>23</CoordinateY>
</WorkLocationCoordinate>
</Coordinates>
<Communities />
</WorkArea>
</WorkArea>
</WorkLocation>
</NOCPlantMapRequest>
以下是我为验证 xml 而创建的架构
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified">
<xsd:element name="NOCPlantMapRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="NOCReference" minOccurs="0" type="xsd:string" />
<xsd:element name="NOCTypeID" minOccurs="0" type="xsd:unsignedByte" />
<xsd:element name="NOCTypeName" minOccurs="0" type="xsd:string" />
<xsd:element name="ApplicationName" minOccurs="0" type="xsd:string" />
<xsd:element name="Applicationtype" minOccurs="0" type="xsd:string" />
<xsd:element name="RelatedNOCRefNumber" minOccurs="0" type="xsd:string" />
<xsd:element name="WorkLocation" minOccurs="1" maxOccurs="1" type="LocationType">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="LocationType">
<xsd:choice>
<xsd:sequence>
<xsd:element name="ParcelNumber" type="ParcelNumberType" />
</xsd:sequence>
<xsd:sequence>
<xsd:element name="WorkArea" type="WorkAreaType" />
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
<xsd:simpleType name="ParcelNumberType">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:complexType name="WorkAreaType">
<xsd:sequence>
<xsd:element name="WorkArea" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Coordinates" minOccurs="1" type="CoordinatesType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="CoordinatesType">
<xsd:sequence>
<xsd:element name="WorkLocationCoordinate" type="WorkLocationCoordinateType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="WorkLocationCoordinateType">
<xsd:sequence>
<xsd:element name="CoordinateX" type="xsd:string" />
<xsd:element name="CoordinateY" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
但是我遇到了类似的错误
Error - Line 6, 12: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 12; cvc-complex-type.2.4.d: Invalid content was found starting with element 'Roads'. No child element is expected at this point.
Error - Line 19, 24: org.xml.sax.SAXParseException; lineNumber: 19; columnNumber: 24; cvc-complex-type.2.4.d: Invalid content was found starting with element 'Communities'. No child element is expected at this point.
我检查了视觉工作室和xml-xsd validation tool
【问题讨论】:
-
你不是just ask this same question吗?如果与非常擅长帮助解决 XSD 问题的 Abel 的所有来回交流都无法解决您的问题,那么您应该重新审视自己的状况 asking questions。