3

我想使用 Emacs 的nxml-mode编辑 XHTML 文件,它可以使用rnc模式进行动态验证。这些都内置在较新的 Emacs 版本中。

但是,我的 XHTML 文件包含来自另一个模式的元素。所以 <foo:foo> 标签是有效的,但只在文档的 <xhtml:head> 内。

目前,nxml 抱怨是因为它使用的 XHTML 模式没有描述 foo 标记。如何创建一个描述与现有 XHTML 模式相关的 foo 标记的新模式,以及如何使用schemas.xml 文件中的模式定位规则自动应用该模式?

即:我想同时使用两种模式来验证文档:内置的 XHTML 规则和一些添加某些命名空间标签的自定义规则。

4

3 回答 3

2

Validator.nu有一个预设的模式,该模式是从最初由 James Clark 开发的 XHTML 模式集修改而来的,其中一个补充是 rdf:RDF in head,因此该模式可能对研究有用。

(我没有处理 nxml 模式模式位置问题的经验。)

于 2008-11-12T23:03:07.557 回答
2

W3C 就是这样。例如,这里是 XHTML+RDFa 的 rng:

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- XHTML+RDFa 1.0 -->

<grammar ns="http://www.w3.org/1999/xhtml"
         xmlns="http://relaxng.org/ns/structure/1.0"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">

<include href="xhtml-datatypes-1.rng"/>
<include href="xhtml-attribs-1.rng"/>
<include href="xhtml-text-1.rng"/>
<include href="xhtml-list-1.rng"/>
<include href="xhtml-object-1.rng"/>
<include href="xhtml-pres-1.rng"/>
<include href="xhtml-edit-1.rng"/>
<include href="xhtml-bdo-1.rng"/>
<include href="xhtml-form-1.rng"/>
<include href="xhtml-table-1.rng"/>
<include href="xhtml-image-1.rng"/>
<include href="xhtml-ssismap-1.rng"/>
<include href="xhtml-events-1.rng"/>
<include href="xhtml-inlstyle-1.rng"/>
<include href="xhtml-base-1.rng"/>
<include href="xhtml-ruby-1.rng"/>
<include href="xhtml-metaAttributes-1.rng"/>

<define name="xhtml.Common.attrib" combine="interleave">
  <optional>
    <attribute name="href">
      <ref name="xhtml.URI.datatype"/>
    </attribute>
  </optional>
  <ref name="xhtml.Metainformation.attrib"/>
</define>

<include href="xhtml-hypertext-1.rng">
    <define name="xhtml.a.attlist">
      <ref name="xhtml.Common.attrib"/>
      <optional>
        <attribute name="charset">
          <ref name="xhtml.Charset.datatype"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="type">
          <ref name="xhtml.ContentType.datatype"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="hreflang">
          <ref name="xhtml.LanguageCode.datatype"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="accesskey">
          <ref name="xhtml.Character.datatype"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="tabindex">
          <ref name="xhtml.Number.datatype"/>
        </attribute>
      </optional>
    </define>
</include>

<include href="xhtml-link-1.rng">
    <define name="xhtml.link.attlist">
      <ref name="xhtml.Common.attrib"/>
      <optional>
        <attribute name="charset">
          <ref name="xhtml.Charset.datatype"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="hreflang">
          <ref name="xhtml.LanguageCode.datatype"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="type">
          <ref name="xhtml.ContentType.datatype"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="media">
          <ref name="xhtml.MediaDesc.datatype"/>
        </attribute>
      </optional>
    </define>
</include>

<include href="xhtml-meta-1.rng">
    <define name="xhtml.meta.attlist">
      <ref name="xhtml.Common.attrib"/>
      <optional>
        <attribute name="http-equiv">
          <data type="NMTOKEN"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="name">
          <data type="NMTOKEN"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="scheme">
          <text/>
        </attribute>
      </optional>
    </define>
</include>

<include href="xhtml-script-1.rng">
    <define name="xhtml.script.attlist">
      <ref name="xhtml.id.attrib"/>
      <ref name="xhtml.Metainformation.attrib"/>
      <optional>
        <attribute name="href">
          <ref name="xhtml.URI.datatype"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="charset">
          <ref name="xhtml.Charset.datatype"/>
        </attribute>
      </optional>
      <attribute name="type">
        <ref name="xhtml.ContentType.datatype"/>
      </attribute>
      <optional>
        <attribute name="src">
          <ref name="xhtml.URI.datatype"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="defer">
          <value>defer</value>
        </attribute>
      </optional>
      <optional>
        <attribute name="xml:space">
          <value>preserve</value>
        </attribute>
      </optional>
    </define>
</include>

<include href="xhtml-style-1.rng">
    <define name="xhtml.style.attlist">
      <ref name="xhtml.title.attrib"/>
      <ref name="xhtml.I18n.attrib"/>
      <ref name="xhtml.id.attrib"/>
      <ref name="xhtml.Metainformation.attrib"/>
      <optional>
        <attribute name="href">
          <ref name="xhtml.URI.datatype"/>
        </attribute>
      </optional>
      <attribute name="type">
        <ref name="xhtml.ContentType.datatype"/>
      </attribute>
      <optional>
        <attribute name="media">
          <ref name="xhtml.MediaDesc.datatype"/>
        </attribute>
      </optional>
      <!-- <optional>
        <attribute name="xml:space">
          <value>preserve</value>
        </attribute>
      </optional> -->
    </define>
</include>

<include href="xhtml-csismap-1.rng">
    <define name="xhtml.area.attlist">
      <ref name="xhtml.Common.attrib"/>
      <ref name="xhtml.shape.attrib"/>
      <ref name="xhtml.coords.attrib"/>
      <optional>
        <attribute name="nohref">
          <value>nohref</value>
        </attribute>
      </optional>
      <attribute name="alt">
        <ref name="xhtml.Text.datatype"/>
      </attribute>
      <optional>
        <attribute name="tabindex">
          <ref name="xhtml.Number.datatype"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="accesskey">
          <ref name="xhtml.Character.datatype"/>
        </attribute>
      </optional>
    </define>
</include>

<include href="xhtml-param-1.rng">
    <define name="xhtml.param.attlist">
      <ref name="xhtml.id.attrib"/>
      <ref name="xhtml.Metainformation.attrib"/>
      <optional>
        <attribute name="href">
          <ref name="xhtml.URI.datatype"/>
        </attribute>
      </optional>
      <attribute name="name"/>
      <optional>
        <attribute name="value"/>
      </optional>
      <optional>
        <attribute name="valuetype">
          <choice>
        <value>data</value>
        <value>ref</value>
        <value>object</value>
          </choice>
        </attribute>
      </optional>
      <optional>
        <attribute name="type">
          <ref name="xhtml.ContentType.datatype"/>
        </attribute>
      </optional>
    </define>
</include>

<include href="xhtml-struct-1.rng">
    <define name="xhtml.title.attlist">
      <ref name="xhtml.Common.attrib"/>
    </define>

    <define name="xhtml.head.attlist">
      <ref name="xhtml.Common.attrib"/>
      <ref name="xhtml.profile.attlist"/>
    </define>

    <define name="xhtml.html.attlist">
      <ref name="xhtml.XHTML.version.attrib"/>
      <ref name="xhtml.Common.attrib"/>
    </define>
</include>

</grammar>

参考

于 2014-05-29T04:50:06.433 回答
2

问题 1:我相信您在这里不想要两个模式,而是一个“包含”另一个模式,并结合了 RelaxNG 教程第 9.2 节中描述的覆盖/组合规则。我自己也在为此苦苦挣扎。

问题2:第二个问题我可以给你更好的答案;nxml-mode 在多个位置之一中查找“schemas.xml”文件,该文件执行模式匹配以将文件与模式相关联。对于最简单的映射,我将此文件放在与 xml 文件相同的目录中:

<?xml version='1.0'?>
<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
  <uri resource="auto.xml" uri="lab.rnc"/>
</locatingRules>

该文件将“auto.xml”文件与“lab.rnc”规范相关联。

于 2010-06-20T19:18:12.497 回答