2012-08-31 47 views
1

我在寫下我的XML文件的模式時遇到了一些問題,這很簡單。構建自定義XML的模式驗證定義

至於建議,我儘量把其他的代碼(我刪除了,因爲如果我被搞亂一切或不...我不能undestrand):

我想不出哪裏的問題我的架構:

<?xml version="1.0" 
     standalone="yes"?> 
<ChangeHistory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <xs:schema id="ChangeHistory" 
      xmlns="" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
    <xs:element name="ChangeHistory" 
       msdata:IsDataSet="true" 
       msdata:MainDataTable="Version" 
       msdata:UseCurrentLocale="true"> 
     <xs:complexType> 
     <xs:element name="Versions"> 
     <xs:complexType> 
      <xs:choice minOccurs="0" maxOccurs="unbounded"> 
      <xs:element name="Version"> 
       <xs:complexType> 
       <xs:sequence> 
        <xs:element name="Edits"> 
        <xs:complexType> 
         <xs:sequence> 
         <xs:element name="Edit"> 
          <xs:complexType> 
          <xs:attribute name="Content" type="xs:string" /> 
          </xs:complexType> 
         </xs:element> 
         </xs:sequence> 
        </xs:complexType> 
        </xs:element> 
       </xs:sequence> 
       <xs:attribute name="Id" type="xs:string" /> 
       </xs:complexType> 
      </xs:element> 
      </xs:choice> 
     </xs:complexType> 
     </xs:element> 
     </xs:complexType> 
    </xs:element> 
    </xs:schema> 
    <Versions> 
    <Version Id="1.0.5 - Coming next!"> 
     <Edits> 
     <Edit Content="Bla bla 1" /> 
     <Edit Content="Bla bla bla" /> 
     </Edits> 
    </Version> 
    <Version Id="1.0.4 - Coming soon!"> 
     <Edits> 
     <Edit Content="First edit of the version" /> 
     <Edit Content="Second edit of the version" /> 
     </Edits> 
    </Version> 
    </Versions> 
</ChangeHistory> 

這個XML是從.NET數據集生成,我認爲這個問題是內部的(所以外面的部分是正確的!)這個元素:

<xs:schema id="ChangeHistory" 
    xmlns="" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 

所有屬性版本編輯元素類型爲xs:string

任何幫助將不勝感激,謝謝。

+0

呃,爲什麼你的XML和模式在同一文檔中? – ThomasRS

+0

因爲這是一個加載爲我的項目的本地化資源的XML,並且Visual Studio可以在編譯期間驗證我的XML ...如果指定了正確的模式! – MAXE

+0

我在模式中看不到元素編輯... – ThomasRS

回答

3

只要使用這個模式,因爲從Visual Studio 20120 XSD工具生成:

<xs:schema id="ChangeHistory" 
     xmlns="" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
<xs:element name="ChangeHistory" 
      msdata:IsDataSet="true" 
      msdata:MainDataTable="Version" 
      msdata:UseCurrentLocale="true"> 
    <xs:complexType> 
    <xs:choice minOccurs="0" 
       maxOccurs="unbounded"> 
     <xs:element name="Versions"> 
     <xs:complexType> 
      <xs:sequence> 
      <xs:element name="Version" 
         minOccurs="0" 
         maxOccurs="unbounded"> 
       <xs:complexType> 
       <xs:sequence> 
        <xs:element name="Edits" 
           minOccurs="0" 
           maxOccurs="unbounded"> 
        <xs:complexType> 
         <xs:sequence> 
         <xs:element name="Edit" 
            minOccurs="0" 
            maxOccurs="unbounded"> 
          <xs:complexType> 
          <xs:attribute name="Content" 
              type="xs:string" /> 
          </xs:complexType> 
         </xs:element> 
         </xs:sequence> 
        </xs:complexType> 
        </xs:element> 
       </xs:sequence> 
       <xs:attribute name="Id" 
           type="xs:string" /> 
       </xs:complexType> 
      </xs:element> 
      </xs:sequence> 
     </xs:complexType> 
     </xs:element> 
    </xs:choice> 
    </xs:complexType> 
</xs:element>