Loading ...
Sorry, an error occurred while loading the content.

Re: [rng-users] Attribute value restrictions

Expand Messages
  • Dingwell, Robert A.
    Unfortunately that does not help me too much as I have schemas that I import the common attributes into that make use of them more then once , with different
    Message 1 of 7 , Jul 1, 2009
    • 0 Attachment
      Re: [rng-users] Attribute value restrictions Unfortunately that does not help me too much as I have schemas that I import the common attributes into that make use of them more then once , with different restrictions.
      What I would really like to be able to do is have some mechanism like xsd complexType that I could then create a restriction on.

      So in xml schema I know I can do something like this,  


        <xs:complexType name="codedValueDef">
          <xs:annotation>
            <xs:documentation> Defines that attributes used for coded values </xs:documentation>
          </xs:annotation>
         
          <xs:attribute name="code" use="required"/>
          <xs:attribute name="codeSystem" use="required"/>
          <xs:attribute name="displayName" use="required"/>
        </xs:complexType>


      And then use it more then once  like so within the same schema.

      <xsd:element name=”value” type="core:codedValueDef">
          
          <xs:complexType >
              <xs:complexContent >
                  
                  <xs:restriction >
                      <xs:attribute name="codeSystem" use="require" fixed="111111"/>
                  </xs:restriction>
               </xs:complexContent>
          </xs:complexType>
          
        </xs:element>

      <xsd:element name=”value2” type="core:codedValueDef">
          
          <xs:complexType >
              <xs:complexContent >
                  
                  <xs:restriction >
                      <xs:attribute name="codeSystem" use="require" fixed="222222"/>
                  </xs:restriction>
               </xs:complexContent>
          </xs:complexType>
          
        </xs:element>

      Is there any way to do something similar to this in relax?

      Thanks

      Rob


      On 7/1/09 1:05 AM, "MURATA Makoto (FAMILY Given)" <EB2M-MRT@...> wrote:


        

        

      One way to overcome the problem is to use <define> as children of
      <include>.

      <include href="common.atts.rng>
       <define name="foo">...</define>
       ....
      </include>

      Here this define statement overrides the define stantement in
      common.atts.rng having the name "foo".

      Cheers,
      Makoto
        
          


    • MURATA Makoto (FAMILY Given)
      ... I am not an expert of W3C XML Schema, but I have thought that you have to copy the content of the original and then modify it rather than describing
      Message 2 of 7 , Jul 8, 2009
      • 0 Attachment
        >
        > So in xml schema I know I can do something like this,
        ...
        > And then use it more then once like so within the same schema.

        I am not an expert of W3C XML Schema, but I have thought that
        you have to copy the content of the original and then modify
        it rather than describing differences. Am I missing something?

        > Unfortunately that does not help me too much as I have schemas that
        >I import the common attributes into that make use of them more then
        >once , with different restrictions.

        You can include the same schema as many times as you want as long as
        each include statement appears in a non-top-level grammar element.

        For example,

        1) root.rng

        This includes common.rng twice.

        <?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="root"/>
        </start>
        <define name="root">
        <element name="root">
        <ref name="foo"/>
        <ref name="bar"/>
        </element>
        </define>
        <define name="foo">
        <element name="foo">
        <grammar>
        <include href="common.rng">
        <define name="toBeOverridden1">
        <attribute name="one">
        <empty/>
        </attribute>
        </define>
        </include>
        </grammar>
        </element>
        </define>
        <define name="bar">
        <element name="bar">
        <grammar>
        <include href="common.rng">
        <define name="toBeOverridden2">
        <empty/>
        </define>
        </include>
        </grammar>
        </element>
        </define>
        </grammar>

        2) common.rng

        This define a group of attributes. Each attribute definition can be
        overriden.

        <?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">

        <start><ref name="common"/></start>

        <define name="common">
        <ref name="toBeOverridden1"/>
        <ref name="toBeOverridden2"/>
        </define>
        <define name="toBeOverridden1">
        <optional>
        <attribute name="one">
        <empty/>
        </attribute>
        </optional>
        </define>

        <define name="toBeOverridden2">
        <optional>
        <attribute name="two">
        <empty/>
        </attribute>
        </optional>
        </define>
        </grammar>


        Cheers,
        Makoto
      • Dingwell, Robert A.
        On 7/8/09 11:18 AM, MURATA Makoto (FAMILY Given) ... You can just describe the differences on a restriction and on an extension you just add whatever else
        Message 3 of 7 , Jul 8, 2009
        • 0 Attachment
          On 7/8/09 11:18 AM, "MURATA Makoto (FAMILY Given)"
          <EB2M-MRT@...> wrote:

          >
          >
          >
          >
          >
          >
          >>
          >> So in xml schema I know I can do something like this,
          > ...
          >> And then use it more then once like so within the same schema.
          >
          > I am not an expert of W3C XML Schema, but I have thought that
          > you have to copy the content of the original and then modify
          > it rather than describing differences. Am I missing something?
          >
          You can just describe the differences on a restriction and on an extension
          you just add whatever else you would like to be included in the type.

          >> Unfortunately that does not help me too much as I have schemas that
          >> I import the common attributes into that make use of them more then
          >> once , with different restrictions.

          Thanks for the multiple include advice, I had tried something similar but we
          are unfortunately in need of producing xsd files as well and have been using
          trang as the transformation engine between rng and xsd. Trang does not
          currently support nested grammars so that will not work for me either,plus
          I'm not really sure that gets at the sort of inheritance I was looking for.
          Seams that you have to completely redefine the entry which can be done much
          more clearly inline by declaring a new element, thanks though.

          What I think would be really nice is if the ref tag had some similar sort of
          restriction/extension mechanism as xsd. I personally find that approach a
          bit more readable/understandable then using nested grammers/overriding
          definitions, but that's just me.

          Thanks again

          Rob




          >
          > You can include the same schema as many times as you want as long as
          > each include statement appears in a non-top-level grammar element.
          >
          > For example,
          >
          > 1) root.rng
          >
          > This includes common.rng twice.
          >
          > <?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="root"/>
          > </start>
          > <define name="root">
          > <element name="root">
          > <ref name="foo"/>
          > <ref name="bar"/>
          > </element>
          > </define>
          > <define name="foo">
          > <element name="foo">
          > <grammar>
          > <include href="common.rng">
          > <define name="toBeOverridden1">
          > <attribute name="one">
          > <empty/>
          > </attribute>
          > </define>
          > </include>
          > </grammar>
          > </element>
          > </define>
          > <define name="bar">
          > <element name="bar">
          > <grammar>
          > <include href="common.rng">
          > <define name="toBeOverridden2">
          > <empty/>
          > </define>
          > </include>
          > </grammar>
          > </element>
          > </define>
          > </grammar>
          >
          > 2) common.rng
          >
          > This define a group of attributes. Each attribute definition can be
          > overriden.
          >
          > <?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">
          >
          > <start><ref name="common"/></start>
          >
          > <define name="common">
          > <ref name="toBeOverridden1"/>
          > <ref name="toBeOverridden2"/>
          > </define>
          > <define name="toBeOverridden1">
          > <optional>
          > <attribute name="one">
          > <empty/>
          > </attribute>
          > </optional>
          > </define>
          >
          > <define name="toBeOverridden2">
          > <optional>
          > <attribute name="two">
          > <empty/>
          > </attribute>
          > </optional>
          > </define>
          > </grammar>
          >
          > Cheers,
          > Makoto
          >
          >
          >
          >
          >
        • MURATA Makoto (FAMILY Given)
          ... I was a member of the W3C XML Schema WG. As far as derivation by restriction is concerned, I strongly believe that you have to write everything rather
          Message 4 of 7 , Jul 8, 2009
          • 0 Attachment
            >
            >
            >

            > You can just describe the differences on a restriction and on an extension
            > you just add whatever else you would like to be included in the type.

            I was a member of the W3C XML Schema WG. As far as derivation by
            restriction is concerned, I strongly believe that you have to write
            everything rather than differences. I checked some tutorials again,
            but I still believe I am not mistaken. (Derivation by extension is
            certainly different.) If you can just describe differences for
            derivation by restriction, please give a real example. Your schema
            fragment shown in your earlier mail does not work.

            > Thanks for the multiple include advice, I had tried something similar but we
            > are unfortunately in need of producing xsd files as well and have been using
            > trang as the transformation engine between rng and xsd. Trang does not
            > currently support nested grammars so that will not work for me either,plus

            Some software expands nested grammars. You might then want to use trang.

            > I'm not really sure that gets at the sort of inheritance I was looking for.

            Certainly it does not. RELAX NG does not provide inheritance.

            > Seams that you have to completely redefine the entry

            No. You can override what you have to override withour redefining
            everything.

            >
            > What I think would be really nice is if the ref tag had some similar sort of
            > restriction/extension mechanism as xsd. I personally find that approach a
            > bit more readable/understandable then using nested grammers/overriding
            > definitions, but that's just me.

            I am not a fan of derivation by restriction. But it might be possible
            to improve RELAX NG so that schema customization becomes even easier.

            Cheers,
            Makoto
          • Dingwell, Robert A.
            On 7/8/09 12:30 PM, MURATA Makoto (FAMILY Given) ... The example was completely off the top of my head not really trying to validate. While it is true that
            Message 5 of 7 , Jul 8, 2009
            • 0 Attachment
              On 7/8/09 12:30 PM, "MURATA Makoto (FAMILY Given)"
              <EB2M-MRT@...> wrote:

              >
              >> You can just describe the differences on a restriction and on an extension
              >> you just add whatever else you would like to be included in the type.
              >
              > I was a member of the W3C XML Schema WG. As far as derivation by
              > restriction is concerned, I strongly believe that you have to write
              > everything rather than differences. I checked some tutorials again,
              > but I still believe I am not mistaken. (Derivation by extension is
              > certainly different.) If you can just describe differences for
              > derivation by restriction, please give a real example. Your schema
              > fragment shown in your earlier mail does not work.

              The example was completely off the top of my head not really trying to
              validate. While it is true that you need to repeat all elements for a
              definition in a restriction you do not have to do the same for all of the
              attributes which you can just describe the derivation and all I'm dealing
              with is a single simple content element with attributes.


              Thanks

              Rob


              >
              >> Thanks for the multiple include advice, I had tried something similar but we
              >> are unfortunately in need of producing xsd files as well and have been using
              >> trang as the transformation engine between rng and xsd. Trang does not
              >> currently support nested grammars so that will not work for me either,plus
              >
              > Some software expands nested grammars. You might then want to use trang.
              >
              >> I'm not really sure that gets at the sort of inheritance I was looking for.
              >
              > Certainly it does not. RELAX NG does not provide inheritance.
              >
              >> Seams that you have to completely redefine the entry
              >
              > No. You can override what you have to override withour redefining
              > everything.
              >
              >>
              >> What I think would be really nice is if the ref tag had some similar sort of
              >> restriction/extension mechanism as xsd. I personally find that approach a
              >> bit more readable/understandable then using nested grammers/overriding
              >> definitions, but that's just me.
              >
              > I am not a fan of derivation by restriction. But it might be possible
              > to improve RELAX NG so that schema customization becomes even easier.
              >
              > Cheers,
              > Makoto
              >
              >
              >
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.