2011-10-11 48 views
2

這是我的第一個問題,這是已經回答了:XML Schema - Is it possible to allow a certain element only once in the whole document?如何用xml模式重新定義xhtml body元素?

現在我要重新定義XHTML的body元素,並添加唯一約束它。這是我redefine.xsdxhtml-struct-1.xsd

<xs:group 
     name="xhtml.html.content"> 
     <xs:sequence> 
      <xs:element 
       name="head" 
       type="xhtml.head.type"/> 
      <xs:element 
       name="body" 
       type="xhtml.body.type"/> 
     </xs:sequence> 
    </xs:group> 

定義我嘗試這樣做:

<xs:redefine schemaLocation="http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd"> 
    <xs:group name="xhtml.html.content"> 
    <xs:sequence> 
     <xs:element name="head" type="xhtml.head.type" /> 
     <xs:element name="body" type="xhtml.body.type" > 
       <xs:unique name="highlander"> 
        <xs:selector xpath=".//mylang:content"/> 
        <xs:field xpath="."/> 
       </xs:unique> 
      </xs:element> 
     </xs:sequence> 
    </xs:group> 
</xs:redefine> 

org.xml.sax.SAXParseException; systemId: file:xhtml-struct-1.xsd; lineNumber:113; columnNumber:35; mg-props-correct.2:針對組''xhtml.html.content_fn3dktizrknc9pi'檢測到循環 。 遞歸跟隨粒子的{term}值會生成一個 粒子,其{term}是該組本身。

我treid其他幾十個變種,但我總是得到奇怪的錯誤,我不明白。我如何用XML Schema重新定義xhtml body元素?

回答

0

重新定義組的工作方式不同。

<xs:redefine schemaLocation="http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd"> 
    <xs:group name="xhtml.html.content"> 
    <xs:sequence> 
     <xs:group ref="xhtml.html.content"> 
     ... additional elements/group to be in this sequence defined here ... 
    </xs:sequence> 
    </xs:group> 
</xs:redefine> 

看起來要重新定義類型「xhtml.body.type」,你應該嘗試做的,與其重新定義組「xhtml.html.content」。

或許這些片斷幫助:

http://www.datypic.com/books/defxmlschema/chapter18.html

+0

對不起,但你的回答沒有幫助我。重新定義xhtml.body.type不起作用,因爲xs:unique只允許作爲xs:element的子元素,所以我無法將唯一定義添加到xhtml.body.type。當我再次引用組時,我只是'添加'其他元素,但我想替換此組中的元素定義 – Janning

+0

您是對的,錯過了詳細信息。抱歉。由於我目前在重新定義XHTML XSD方面遇到類似的麻煩,我也對這個問題感興趣。我認爲這與XSD有關,它支持重新定義超集或子集,但不包含與以前相同的元素。你有沒有試過做兩步重定義 - 重新定義第一個包含XSD頭元素的子集,在第二個XSD中重新定義爲超集重新集成所有修改的主體元素? – soletan

0

您是否嘗試過不同的解析器/驗證?

關於我的有點類似問題上W3C's XMLSchema Dev Mailing List張貼有個私人的響應(因此沒有前鏈接存檔可用)告訴我有關運行有不同的結果,不同的解析器響應的測試:libxml的v20708和MSXML v20090415成功驗證而的Xerces-J 2.11和Saxon 9.2都與XSD有問題。