RelaxNG (rnc) 模式来扩展 XHTML

发布于 2024-07-08 15:23:22 字数 642 浏览 13 评论 0原文

我想使用 Emacs 的 nxml-mode 编辑 XHTML 文件,它可以使用 rnc 用于动态验证的架构。 这全部内置于较新的 Emacs 版本中。

但是,我的 XHTML 文件包含来自另一个架构的元素。 所以标签有效,但仅在内有效。 该文件的。

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

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

I would like to edit XHTML files using Emacs' nxml-mode which can use rnc schemas for on the fly validation. This is all built in to newer Emacs versions.

However, my XHTML files contain elements from another schema. So <foo:foo> tags are valid, but only within the <xhtml:head> of the document.

Currently, nxml complains because the XHTML schema it is using does not describe the foo tag. How do I create a new schema which describes the foo tag in relation to the existing XHTML schema, and how do I apply that schema automatically using schema locating rules in the schemas.xml file?

ie: I would like to validate a document using two schemas simultaneously: the built-in XHTML rules, and some custom rules which add certain namespaced tags.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不即不离 2024-07-15 15:23:22

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

(我对 nxml 模式架构位置问题没有经验。)

Validator.nu has a preset schema that is modified from the the XHTML schema set originally developed by James Clark and one of the additions is rdf:RDF in head, so the schema might be useful to study.

(I have no experience with nxml-mode schema location issues.)

音盲 2024-07-15 15:23:22

问题 1:我相信您不希望这里有两个模式,而是需要一个模式“包含”另一个模式,并结合 RelaxNG 教程。 我自己也在努力解决这个问题。

问题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”规范相关联。

Problem 1: I believe that you don't want two schemas here, but rather one schema that "include"s another, combined with the overriding/combination rules described in section 9.2 of the RelaxNG tutorial. I'm wrestling with this myself.

Problem 2: I can give you a better answer to the second problem; nxml-mode looks in one of a number of locations for a "schemas.xml" file that performs pattern-matching to associate files with schemas. For the simplest possible mapping, I have this file in the same dir as the xml file:

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

This file associates the "auto.xml" file with the "lab.rnc" specification.

半山落雨半山空 2024-07-15 15:23:22

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>

参考

The W3C has just the thing. For example, here is the rng for XHTML+RDFa:

<?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>

References

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文