Domanda

Is there a way to write that there are completely no restrictions on content of an element in Relax NG?

In XML Schema something like this is apparently possible with

<xs:sequence>
   <xs:any namespace="##targetNamespace" processContents="lax"
       minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>

Can I do an equivalent of this in Relax NG?

È stato utile?

Soluzione

I propose this solution, dividing attributes and elements declaration, and using mixed element to allow mixed content.

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
    <start>
        <ref name="anyElement"/>
    </start>
    <define name="anyElement">
        <element>
            <anyName/>
            <ref name="anyAttributes"/>
            <mixed>
                <zeroOrMore>
                    <ref name="anyElement"/>
                </zeroOrMore>
            </mixed>
        </element>
    </define>
    <define name="anyAttributes">
        <zeroOrMore>
            <attribute>
                <anyName/>
            </attribute>
        </zeroOrMore>
    </define>
</grammar>

Altri suggerimenti

Okay, I don't know if this the best way, but I have adapted this from "any" definition in Relax NG spec.

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
    xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
    datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
    <start>
        <ref name="Anything"/>
    </start>
    <define name="Anything">
        <zeroOrMore>
            <choice>
                <element>
                    <anyName/>
                    <ref name="Anything"/>
                </element>
                <attribute>
                    <anyName/>
                </attribute>
                <text/>
            </choice>
        </zeroOrMore>
    </define>
</grammar>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top