-1
需要XSI屬性我有以下模式讓XS和個XML:在XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="translator">
...
</xs:element>
</xs:schema>
我如何定義以下所需的屬性,所以添加新的翻譯節點時,這些屬性也將被添加?
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Translator.xsd"
如果我把它們放在XSD,這樣
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="translator">
<xs:attribute name="xmlns:xsi" type="xs:string" default="http://www.w3.org/2001/XMLSchema-instance"/>
<xs:attribute name="xsi:noNamespaceSchemaLocation" type="xs:string" default="Translator.xsd"/>
</xs:element>
</xs:schema>
下面的問題是由Xerces的報道
[Error] :678:114: s4s-att-invalid-value: Invalid attribute value for 'name' in element 'attribute'. Recorded reason: cvc-datatype-valid.1.2.1: 'xmlns:xsi' is not a valid value for 'NCName'.
[Error] :678:114: src-attribute.3.1: One of 'ref' or 'name' must be present in a local attribute declaration.
[Error] :679:117: s4s-att-invalid-value: Invalid attribute value for 'name' in element 'attribute'. Recorded reason: cvc-datatype-valid.1.2.1: 'xsi:noNamespaceSchemaLocation' is not a valid value for 'NCName'.
[Error] :679:117: src-attribute.3.1: One of 'ref' or 'name' must be present in a local attribute declaration.
我只想在創建新的XML文件時將它們從XSD轉移到XML。 – nucandrei
在進行建議更改後,在Xerces日誌中顯示以下警告:678:89:src-resolve.4.2:解析組件'xsi:noNamespaceSchemaLocation'時出現錯誤。檢測到'xsi:noNamespaceSchemaLocation'位於命名空間'http://www.w3.org/2001/XMLSchema-instance'中,但該命名空間中的組件不能從模式文檔'null'中引用。如果這是不正確的命名空間,則可能需要更改'xsi:noNamespaceSchemaLocation'的前綴。如果這是正確的名稱空間,那麼應該將一個適當的'import'標籤添加到'null'中。 – nucandrei
嗨nucandrei,你可以嘗試使用http://stackoverflow.com/questions/17094247/where-is-the-xsd-file-for-http-www-w3-org-2001-xmlschema-但請記住,這是所有未經審查的,未經推薦的領土和加工商可能不會像您預期的那樣行事。 –