我想做一個XML模式來驗證我的XML,第一次。我無法在XML模式中包含屬性。 (http://www.w3.org/2001/XMLSchema-instance使用)
<?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(通知 「-instance
」 和 「SectionNumber="0"
」)開始
<?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
」,我擺脫了a bove錯誤,但是我不能使用屬性「<xsi:attribute name="SectionNumber" type="xsi:Integer"/>
」的代碼。
我甚至不知道我的真正問題是-instance
部分,還是有另一種方法在模式中編寫/包含屬性。我該如何解決這個問題?
謝謝,這是一個非常好的答案。這很有道理。你的意思是你把前綴改成'xs'而不是'ns'吧?我會馬上開始測試。 – radbyx 2012-04-20 10:38:33
對,我的意思是'xs',修正了。 – svick 2012-04-20 10:45:03
此外,現在它是有道理的,爲什麼我讀的所有使用'xs'而不是'xsi'就像我做了哈哈:) – radbyx 2012-04-20 10:55:18