Accepting any Element in RelaxNG

2008.03.07 22:21

Sometimes I need a part of my schema to accept anything. For example, I allow a user to input Markdown, and I place the generated HTML inside of a “content” element. I don’t want to specify all of the possible HTML elements in my schema.

This is in the RelaxNG tutorial, but I’m sick of looking it up there every time I forget.

I define this type:

<define name="any">
  <element>
    <anyName/>
    <zeroOrMore>
      <choice>
        <attribute>
          <anyName/>
        </attribute>
        <text/>
        <ref name="any"/>
      </choice>
    </zeroOrMore>
  </element>
</define>

Then reference it like this:

<element name="content">
  <oneOrMore>
    <ref name="any"/>
  </oneOrMore>
</element>

That’s it.

Comments? (moderated as hell)

allowed HTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>