-1
嘿,我在指定文檔範圍的定義屬性時遇到困難。我使用屬性內部的屬性使用ref
屬性,我相信它應該可以工作。但是當我嘗試驗證我的測試XML文件時,我只是得到一個錯誤,說明屬性沒有被定義。XSD:文檔範圍的屬性
如果我用屬性定義替換ref
-屬性的內聯聲明或甚至attributeGroup
,那麼它就神奇地起作用。 Visual Studio的自動完成建議我再次使用某個前綴導入名稱空間,並希望在屬性上使用該前綴,儘管名稱空間本身已作爲默認名稱空間導入(並且是唯一使用的名稱空間)。
我已經煮了我的XML和我的XSD文件都差不多,所以這是留給:
<?xml version="1.0" encoding="utf-8"?>
<foo xmlns="http://example.com/test" attr="xy" />
<!-- Visual Studio autocompletes to this, which works too:
<foo xmlns="http://example.com/test" a:attr="xy" xmlns:a="http://example.com/test" />
-->
這是方案:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="http://example.com/test" targetNamespace="http://example.com/test"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:attribute name="attr" type="xs:string" />
<xs:attributeGroup name="attrGroup">
<xs:attribute name="attr" type="xs:string" />
</xs:attributeGroup>
<xs:element name="foo">
<xs:complexType>
<xs:attribute ref="attr" />
<!-- These two examples work:
<xs:attributeGroup ref="attrGroup" />
<xs:attribute name="attr" type="xs:string" />
-->
</xs:complexType>
</xs:element>
</xs:schema>
什麼是這個原因行爲和我能做些什麼來解決它?
啊,謝謝。所以每個默認屬性都不在任何名稱空間中? – poke 2011-03-30 19:32:45