混合 HTML 和 XML 的架构(不是 "including XHTML in XML")

Schema for mixing HTML and XML (not "including XHTML in XML")

在 XML 文档中嵌入一些 XHTML 很容易,就像这样:

<?xml version="1.0"?> 
<mannual:product xmlns:mannual="http://product/mannual" 
     xmlns="http://www.w3.org/1999/xhtml"> 
  ...
  <mannual:instruction>
    <p>Before proceeding, 
       <strong>make sure you put on your safety goggles</strong>.
       Start by unlocking the airlock...
    </p>
  </mannual:instruction>
  ....
</mannual:product>

这可以通过 XML 架构 <import> 导入 XHTML 的 xsd 文件并定义元素 <mannual:instruction> 以具有类型 xhtml.div.type

但是如果我们想混合使用 XML 和 HTML 怎么办?像这样:

<?xml version="1.0"?> 
<mannual:product xmlns:mannual="http://product/mannual" 
     xmlns="http://www.w3.org/1999/xhtml"> 
  ...
  <mannual:instruction>
    <p><mannual:information>Before proceeding, 
         <strong>make sure you put on your safety goggles</strong>.
       </mannual:information>
       <mannual:action>
         Start by unlocking the airlock...
       </mannual:action>
    </p>
  </mannual:instruction>
  ....
</mannual:product>

如您所见,在 XHTML 段中使用了一些 XML 元素(<information><action>)。在这种情况下,将 instruction 定义为 xhtml.div.type 不会通过验证。我们如何定义架构以允许这种灵活性?

语法需要明确的定义;关于混合的挥手描述不会削减它。

你的HTML和XML"mix"没有这么明确的定义。要查看此内容,只需查看示例的 p 元素即可。 HTML 没有将 p 元素定义为具有 manual:information 个子元素。

所以,你可以

  • 卷起袖子为你的新语法写一个合适的语法,或者
  • Punt,并使用 xsd:any 允许在您希望混合 HTML 和 XML 的地方使用任何格式正确的标记,从而放弃针对那里的实际语法进行验证的能力。