0

I have a document like this:

<d:block xmlns:d="D" xmlns:b="B" xmlns="default" name="popover">
  <d:description>...</d:description>
  <d:sample>
    <b:popover>
      ...some b:stuff...
    </b:popover>
   </d:sample>
</d:block>

Schema for this document looks like:

<grammar xmlns="http://relaxng.org/ns/structure/1.0">
    <start>
        <element name="block" ns="D">
            <attribute name="name"/>
            <element name="description">
                <text/>
            </element>
            <element name="sample">
                <ref name="anything"/>
            </element>
        </element>
    </start>
    <define name="anything">
        <element>
            <anyName>
                <except>
                    <nsName ns="D"/>
                </except>
            </anyName>
            <zeroOrMore>
                <choice>
                    <attribute>
                        <anyName/>
                    </attribute>
                    <text/>
                    <ref name="anything"/>
                </choice>
            </zeroOrMore>
        </element>
    </define>
</grammar>

"Anything" literally means anything but D-namespaced.

And I want to create another schema for B namespace to use it against any arbitrary XML containing B:namespace.

How to create Schema for the namespace, not for the complete document?

Can't get this.

4

1 回答 1

0

A kind of schema like that should work. You just have to define the elements for B namespace in the define element named BElements.

<grammar xmlns="http://relaxng.org/ns/structure/1.0">
    <start>
      <ref name="anythingOrB"/>
    </start>
    <define name="anythingOrB">
        <choice>
            <ref name="BElements"/>
            <ref name="anythingExceptB"/>
        </choice>
    </define>
    <define name="anythingExceptB">
        <element>
            <anyName>
                <except>
                    <nsName ns="B"/>
                </except>
            </anyName>
            <zeroOrMore>
                <choice>
                    <attribute>
                        <anyName/>
                    </attribute>
                    <text/>
                    <ref name="anythingOrB"/>
                </choice>
            </zeroOrMore>
        </element>    
    </define>
    <define name="BElements">
        <choice>
            <element name="elt1" ns="B">
                <empty/>
            </element>
            <element name="elt2" ns="B">
                <empty/>
            </element>
        </choice> 
    </define>
</grammar>
于 2012-09-20T09:49:54.593 回答