[relaxng-user] Inheritance rant.

Tor Helland tor at helland.org
Thu Jan 22 13:39:47 ICT 2004


> The atom spec calls for an author element.
>  if defined as a child of feed, it remains in force until
>   overriden by providing an author child of entry, i.e. inherited.
>  if not defined in feed,
>    it must be provided by each entry child.
>  Seems a bit of a waste.
>   I couldn't figure out how to validate it in relax ng,
>    hence had to step out to Schematron.

The schema appended at the end, and the 2 xml files, does this (I think, not
an expert). Both xml files validate with Jing.
And omitting the author element raises an error.

> Is it reasonable to identify (somehow)
> that element X is 'inheritable'?
> Or that attribute Y is inheritable,
>   until overriden.

The Relax NG schemas for xhtml 2.0 use a <define> for common attributes.
It's easy to have one for common elements. They don't mention any
inheritable meaning right there, but I guess that has to do with how the
application uses the data, and not validity. (big words from a beginner ;-)

-tor (examples following)

<?xml version="1.0" encoding="utf-8"?>
<grammar ns="dummy" xmlns="http://relaxng.org/ns/structure/1.0">
  <start>
    <choice>
      <ref name="feed-element"/>
    </choice>
  </start>

  <define name="feed-element">
    <element name="feed">
      <choice>
        <ref name="feed-with-author-content"/>
        <ref name="feed-without-author-content"/>
      </choice>
    </element>
  </define>

  <define name="feed-with-author-content">
    <interleave>
      <ref name="author-element"/>
      <oneOrMore>
        <ref name="entry-element"/>
      </oneOrMore>
    </interleave>
  </define>
  <define name="feed-without-author-content">
    <interleave>
      <oneOrMore>
        <ref name="entry-with-author-element"/>
      </oneOrMore>
    </interleave>
  </define>

  <define name="author-element">
      <element name="author"><text/></element>
  </define>

  <define name="entry-element">
    <element name="entry">
      <interleave>
        <optional>
          <ref name="author-element"/>
        </optional>
        <ref name="entry-common-content"/>
      </interleave>
    </element>
  </define>
  <define name="entry-with-author-element">
    <element name="entry">
      <interleave>
        <ref name="author-element"/>
        <ref name="entry-common-content"/>
      </interleave>
    </element>
  </define>
  <define name="entry-common-content">
    <element name="someElement"><text/></element>
  </define>

</grammar>


<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="dummy">
  <author/>
  <entry><someElement/></entry>
  <entry><someElement/></entry>
  <entry><someElement/></entry>
</feed>


<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="dummy">
  <entry><author/><someElement/></entry>
  <entry><author/><someElement/></entry>
  <entry><author/><someElement/></entry>
</feed>


<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="dummy">
  <author/>
  <entry><author/><someElement/></entry>
  <entry><author/><someElement/></entry>
  <entry><someElement/></entry>
</feed>

-------theEnd



More information about the relaxng-user mailing list