Схема RelaxNG (rnc) для расширения XHTML

Я хотел бы редактировать файлы XHTML с помощью режима nxml в Emacs, который может использовать rnc схемы для проверки на лету. Все это встроено в новые версии Emacs.

Однако мои файлы XHTML содержат элементы из другой схемы. Итак, теги ‹foo: foo› допустимы, но только в пределах ‹xhtml: head› документа.

В настоящее время nxml жалуется, потому что схема XHTML, которую он использует, не описывает тег foo. Как создать новую схему, описывающую тег foo по отношению к существующей схеме XHTML, и как применить эту схему автоматически с помощью правила размещения схемы в файле schemas.xml?

то есть: я хотел бы проверить документ, используя одновременно две схемы: встроенные правила XHTML и некоторые настраиваемые правила, которые добавляют определенные теги с пространством имен.


person Community    schedule 12.11.2008    source источник


Ответы (3)


Validator.nu имеет предустановленная схема, которая изменена из набора схем XHTML, первоначально разработанного Джеймсом Кларком, и одним из дополнений является rdf: RDF в заголовке, поэтому схема может быть полезной учиться.

(У меня нет опыта работы с проблемами расположения схемы в nxml-режиме.)

person hsivonen    schedule 12.11.2008

Проблема 1. Я считаю, что вам нужны здесь не две схемы, а одна схема, которая «включает» другую, в сочетании с правилами переопределения / комбинирования, описанными в разделе 9.2 документа руководство по 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».

person John Clements    schedule 20.06.2010

У W3C есть именно то, что вам нужно. Например, вот rng для 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>

Ссылки

person Community    schedule 29.05.2014