鑑於架構(匿名,感興趣的關鍵點被重命名,其餘略):爲什麼此XDocument驗證失敗?
Dim xDocument =
<x:inspec xmlns:x='the_right_namespace'>
<a_collection_property/>
<another_collection_property/>
</x:inspec>
驗證失敗的:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="inspec"
targetNamespace="the_right_namespace"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:element name="inspec">
<xs:complexType>
<xs:all>
<xs:element name="a_scalar_property" type="xs:int"/>
<xs:element name="a_collection_property">
<xs:complexType>
<snip>
</xs:complexType>
</xs:element>
<xs:element name="another_collection_property">
<xs:complexType>
<snip>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
和實例(使用VB XML文本聲明)消息The element 'inspec' in namespace 'the_right_namespace' has incomplete content. List of possible elements expected: 'a_scalar_property'.
爲什麼?根據W3Schools的all
元素:
「all元素指定子元素可以以任何順序出現,並且每個子元素可以出現零次或一次。」
省略a_scalar_property
與將其包括零次相同。爲什麼這個文件無法驗證?
不要說'發佈完整的代碼' - 這不是我的知識產權,我有一個很好的理由匿名。除此之外沒有其他的東西,我用這個最小的例子進行了測試,結果相同。
相關:(我不是說他們必然是錯在這種情況下)http://w3fools.com/ – JJJ
謝謝 - 我還沒有發現W3School可以很好地利用我自己,但是將它作爲可能大家都聽說過的參考 - 並且您真的希望頁面上的第一句關於Xml Schema的基本片斷是正確的! –