我正在尝试制作一个 XML Schema 来验证我的 XML,这是第一次。
我的 XML 的开始(注意“ -instance
”和“ SectionNumber="0"
”):
<?xml version="1.0" encoding="utf-8"?>
<CrystalReport
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:crystal-reports:schemas:report-detail
http://www.businessobjects.com/products/xml/CR2008Schema.xsd"
xmlns="urn:crystal-reports:schemas:report-detail"
>
<ReportHeader>
<Section SectionNumber="0">
<Text Name="Text9">
...
我的 XML 模式(注意第 2、3 和 20 行):
<?xml version="1.0" encoding="utf-8"?>
<xsi:schema id="XMLSchema_varslings1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:crystal-reports:schemas:report-detail"
elementFormDefault="qualified"
targetNamespace="urn:crystal-reports:schemas:report-detail">
<xsi:element name="CrystalReport" type="CrystalReportType"/>
<xsi:complexType name="CrystalReportType">
<xsi:sequence maxOccurs="unbounded">
<xsi:element name="ReportHeader" type="ReportHeaderType"/>
</xsi:sequence>
</xsi:complexType>
<xsi:complexType name="ReportHeaderType">
<xsi:sequence>
<xsi:element name="Section" type="SectionType"/>
<!-- This is line 19....................................... -->
<xsi:attribute name="SectionNumber" type="xsi:Integer"/>
</xsi:sequence>
</xsi:complexType>
<xsi:complexType name="SectionType">
<xsi:sequence maxOccurs="unbounded">
<xsi:element name="Text" type="TextType" />
</xsi:sequence>
</xsi:complexType>
<xsi:complexType name="TextType">
<xsi:sequence maxOccurs="unbounded">
<xsi:element name="TextValue" type="xsi:string" />
</xsi:sequence>
</xsi:complexType>
</xsi:schema>
我收到此错误,我无法解决:“ The root element of a W3C XML Schema should be <schema> and its namespace should be 'http://www.w3.org/2001/XMLSchema'.
”
如果我-instance
从架构中删除“”,我会摆脱上述错误,但我不能使用属性“ <xsi:attribute name="SectionNumber" type="xsi:Integer"/>
”的代码。
我什至不知道我真正的问题是-instance
部分还是有另一种方法可以在模式中写入/包含属性。我该如何解决这个问题?