8 Replies Latest reply on Feb 25, 2020 11:17 AM by odie_63

    Is it possible to impose required constraint at value level?

    Rajneesh S-Oracle

      Hello All,

       

      Is it possible to impose required constraint at value level?

      for example in below xml, I wnt to make sure value for alias1, coli1 and operator is always populated in condition element within where element.

       

      functionalView name="CLAIMS_FV"  description="Learning Purpose">

        <columns>

          <column name="CLAI.CODE"   columnAlias="CODE"  description="The code of the claim" />

          <column name="CLLI.CODE"   columnAlias="LINE_CODE"  description="The code of the claim line" />

          <column name="PROC.CODE"   columnAlias="PROC_CODE"  description="The code of the claim line procedure" />

        </columns>

        <fromviews>

          <fromview name="CLAIMS_V" alias="CLAI" />

          <fromview name="LINES_V" alias="CLLI" />

          <fromview name="PROC_V" alias="PROC" />

          <fromview name="PROV_V" alias="PROV" />

          <fromview name="FORMS_V" alias="CLFO"/>

          <fromview name="FORMTYPES_V" alias="CFTY"/>

        </fromviews>

        <joins>

          <join  alias1="CLLI" col1="CLAI_ID" condition="="  alias2="CLAI" col2="ID"/>

          <join  alias1="CLFO" col1="ID" condition="="  alias2="CFTY" col2="CLFO_ID"/>

          <join  alias1="CFTY" col1="ID" condition="="  alias2="PROC" col2="CFTY_ID"/>

          <leftouterjoin  alias1="PROV" col1="ID" condition="="  alias2="CLAI" col2="PROVIDER_ID"/>

        </joins>

        <where>

          <condition alias1="CFTY" col1="CODE"  operator="="  string=""   number="" date= ""    />

        </where>

      </functionalView>

       

      Below is respective XSD for reference:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

        <xs:element name="functionalView" >

          <xs:complexType>

            <xs:sequence>

              <xs:element name="columns">

                <xs:complexType>

                  <xs:sequence>

                    <xs:element name="column" maxOccurs="unbounded" minOccurs="1">

                      <xs:complexType>

                        <xs:simpleContent>

                          <xs:extension base="xs:string">

                            <xs:attribute type="xs:string" name="name" use="required"/>

                            <xs:attribute type="xs:string" name="columnAlias" use="required"/>

                            <xs:attribute type="xs:string" name="description" use="required"/>

                          </xs:extension>

                        </xs:simpleContent>

                      </xs:complexType>

                    </xs:element>

                  </xs:sequence>

                </xs:complexType>

              </xs:element>

              <xs:element name="fromviews" maxOccurs="1" minOccurs="1">

                <xs:complexType>

                  <xs:sequence>

                    <xs:element name="fromview" maxOccurs="unbounded" minOccurs="2">

                      <xs:complexType>

                        <xs:simpleContent>

                          <xs:extension base="xs:string">

                            <xs:attribute type="xs:string" name="name" use="required"/>

                            <xs:attribute type="xs:string" name="alias" use="required"/>

                          </xs:extension>

                        </xs:simpleContent>

                      </xs:complexType>

                    </xs:element>

                  </xs:sequence>

                </xs:complexType>

              </xs:element>

              <xs:element name="joins" maxOccurs="1" minOccurs="1">

                <xs:complexType>

                  <xs:choice maxOccurs="unbounded" minOccurs="1">

                    <xs:element name="join" maxOccurs="unbounded" minOccurs="0">

                      <xs:complexType>

                        <xs:simpleContent>

                          <xs:extension base="xs:string">

                            <xs:attribute type="xs:string" name="alias1" use="required"/>

                            <xs:attribute type="xs:string" name="col1" use="required"/>

                            <xs:attribute type="xs:string" name="condition" use="required"/>

                            <xs:attribute type="xs:string" name="alias2" use="required"/>

                            <xs:attribute type="xs:string" name="col2" use="required"/>

                          </xs:extension>

                        </xs:simpleContent>

                      </xs:complexType>

                    </xs:element>

                    <xs:element name="leftouterjoin" maxOccurs="unbounded" minOccurs="0">

                      <xs:complexType>

                        <xs:simpleContent>

                          <xs:extension base="xs:string">

                            <xs:attribute type="xs:string" name="alias1" use="required"/>

                            <xs:attribute type="xs:string" name="col1" use="required"/>

                            <xs:attribute type="xs:string" name="condition" use="required"/>

                            <xs:attribute type="xs:string" name="alias2" use="required"/>

                            <xs:attribute type="xs:string" name="col2" use="required"/>

                          </xs:extension>

                        </xs:simpleContent>

                      </xs:complexType>

                    </xs:element>

                  </xs:choice>

                </xs:complexType>

              </xs:element>

              <xs:element name="where" maxOccurs="1" minOccurs="0">

                <xs:complexType>

                  <xs:sequence>

                    <xs:element name="condition" maxOccurs="unbounded" minOccurs="1">

                      <xs:complexType>

                        <xs:simpleContent>

                          <xs:extension base="xs:string">

                            <xs:attribute type="xs:string" name="alias1" use="required"/>

                            <xs:attribute type="xs:string" name="col1" use="required"/>

                            <xs:attribute type="xs:string" name="operator" use="required"/>

                            <xs:attribute type="xs:string" name="string" use="optional"/>

                            <xs:attribute type="xs:string" name="number" use="optional"/>

                            <xs:attribute type="xs:string" name="date" use="optional"/>

                          </xs:extension>

                        </xs:simpleContent>

                      </xs:complexType>

                    </xs:element>

                  </xs:sequence>

                </xs:complexType>

              </xs:element>

            </xs:sequence>

            <xs:attribute type="xs:string" name="name"/>

            <xs:attribute type="xs:string" name="description"/>

          </xs:complexType>

        </xs:element>

      </xs:schema>

       

       

      Thanks,

      Rajneesh

        • 1. Re: Is it possible to impose required constraint at value level?
          odie_63

          You can declare this simpleType and base the required attributes on it :

           

          <xs:simpleType name="notEmptyString">
            <xs:restriction base="xs:string">
              <xs:minLength value="1"/>
            </xs:restriction>
          </xs:simpleType>
          

           

          and then :

          <xs:attribute type="notEmptyString" name="alias1" use="required"/>
          <xs:attribute type="notEmptyString" name="col1" use="required"/>
          <xs:attribute type="notEmptyString" name="operator" use="required"/>
          

           

          BTW, your schema is a little overcomplicated.

          If elements cannot have text content, you don't need to use simpleContent, just declare a list of xs:attribute inside an xs:complexType.

          See my examples in your previous thread.

          1 person found this helpful
          • 2. Re: Is it possible to impose required constraint at value level?
            Rajneesh S-Oracle

            Thanks odie_63,

            Let me perform POC as per your comment.

            BTW any guess if Schematron is allowed/supported in XMLDB?

             

            I heard  that Schematron provided much more flexibility than simple XML, is that true?

             

            Thanks,

            Rajneesh

            • 3. Re: Is it possible to impose required constraint at value level?
              odie_63

              No, Schematron is not supported out-of-the-box.

              However, we can roll out our own implementation based on XSLT or XQuery.

               

              I heard  that Schematron provided much more flexibility than simple XML, is that true?

              Well, in a sense yes.

              In particular, Schematron provides a way to define assertions, which is a most useful feature for complex validation scenarios.

              1 person found this helpful
              • 4. Re: Is it possible to impose required constraint at value level?
                Rajneesh S-Oracle

                Hi odie_63,

                 

                Getting below error when tried to register below XSD (changes to previous registered XSD are highlighted in bold), I am not sure if I am correctly defined simple type or not:

                Enhanced XSD:

                 

                <?xml version="1.0" encoding="UTF-8"?>

                <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

                  <xs:element name="functionalView">

                    <xs:complexType>

                      <xs:sequence>

                        <xs:element name="columns">

                          <xs:complexType>

                            <xs:sequence>

                              <xs:element name="column" maxOccurs="unbounded" minOccurs="1">

                                <xs:complexType>

                                  <xs:simpleContent>

                                    <xs:extension base="xs:string">

                                      <xs:attribute type="xs:string" name="name" use="required"/>

                                      <xs:attribute type="xs:string" name="columnAlias" use="required"/>

                                      <xs:attribute type="xs:string" name="description" use="required"/>

                                    </xs:extension>

                                  </xs:simpleContent>

                                </xs:complexType>

                              </xs:element>

                            </xs:sequence>

                          </xs:complexType>

                        </xs:element>

                        <xs:element name="fromviews" maxOccurs="1" minOccurs="1">

                          <xs:complexType>

                            <xs:sequence>

                              <xs:element name="fromview" maxOccurs="unbounded" minOccurs="2">

                                <xs:complexType>

                                  <xs:simpleContent>

                                    <xs:extension base="xs:string">

                                      <xs:attribute type="xs:string" name="name" use="required"/>

                                      <xs:attribute type="xs:string" name="alias" use="required"/>

                                    </xs:extension>

                                  </xs:simpleContent>

                                </xs:complexType>

                              </xs:element>

                            </xs:sequence>

                          </xs:complexType>

                        </xs:element>

                        <xs:element name="joins" maxOccurs="1" minOccurs="1">

                          <xs:complexType>

                            <xs:choice maxOccurs="unbounded" minOccurs="1">

                              <xs:element name="join" maxOccurs="unbounded" minOccurs="0">

                                <xs:complexType>

                                  <xs:simpleContent>

                                    <xs:extension base="xs:string">

                                      <xs:attribute type="xs:string" name="alias1" use="required"/>

                                      <xs:attribute type="xs:string" name="col1" use="required"/>

                                      <xs:attribute type="xs:string" name="condition" use="required"/>

                                      <xs:attribute type="xs:string" name="alias2" use="required"/>

                                      <xs:attribute type="xs:string" name="col2" use="required"/>

                                    </xs:extension>

                                  </xs:simpleContent>

                                </xs:complexType>

                              </xs:element>

                              <xs:element name="leftouterjoin" maxOccurs="unbounded" minOccurs="0">

                                <xs:complexType>

                                  <xs:simpleContent>

                                    <xs:extension base="xs:string">

                                      <xs:attribute type="xs:string" name="alias1" use="required"/>

                                      <xs:attribute type="xs:string" name="col1" use="required"/>

                                      <xs:attribute type="xs:string" name="condition" use="required"/>

                                      <xs:attribute type="xs:string" name="alias2" use="required"/>

                                      <xs:attribute type="xs:string" name="col2" use="required"/>

                                    </xs:extension>

                                  </xs:simpleContent>

                                </xs:complexType>

                              </xs:element>

                            </xs:choice>

                          </xs:complexType>

                        </xs:element>

                        <xs:simpleType name="nonEmptyString">

                    <xs:restriction base="xs:string">

                      <xs:minLength value="1"/>

                    </xs:restriction>

                  </xs:simpleType>

                        <xs:element name="where" maxOccurs="1" minOccurs="0">

                          <xs:complexType>

                            <xs:sequence>

                              <xs:element name="condition" maxOccurs="unbounded" minOccurs="1">

                                <xs:complexType>

                                      <xs:attribute type="nonEmptyString" name="alias1" use="required"/>

                                      <xs:attribute type="nonEmptyString" name="col1" use="required"/>

                                      <xs:attribute type="nonEmptyString" name="operator" use="required"/>

                                      <xs:attribute type="xs:string" name="string" use="optional"/>

                                      <xs:attribute type="xs:string" name="number" use="optional"/>

                                      <xs:attribute type="xs:string" name="date" use="optional"/>

                                </xs:complexType>

                              </xs:element>

                            </xs:sequence>

                          </xs:complexType>

                        </xs:element>

                      </xs:sequence>

                      <xs:attribute type="xs:string" name="name"/>

                      <xs:attribute type="xs:string" name="description"/>

                    </xs:complexType>

                  </xs:element>

                </xs:schema>

                 

                Thanks,

                Rajneesh

                • 5. Re: Is it possible to impose required constraint at value level?
                  odie_63

                  Unlike anonymous type definitions you've used elsewhere thoughout the schema, 'nonEmptyString' type must be defined at the top level :

                   

                  <?xml version="1.0" encoding="UTF-8"?>
                  <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
                  
                    <xs:simpleType name="nonEmptyString">
                      <xs:restriction base="xs:string">
                        <xs:minLength value="1"/>
                      </xs:restriction>
                    </xs:simpleType>
                  
                    <xs:element name="functionalView">
                      <xs:complexType>
                        <xs:sequence>
                          ...
                  
                  1 person found this helpful
                  • 6. Re: Is it possible to impose required constraint at value level?
                    Rajneesh S-Oracle

                    Thanks it got registered successfully:

                     

                    • 7. Re: Is it possible to impose required constraint at value level?
                      Rajneesh S-Oracle

                      Hi odie_63,

                       

                      One more observation, I can not impose - maxOccurs="1" minOccurs="1" with parent element <xs:element name="functionalView">, however it is allowed in all child elements.

                      In case I need to ensure that below is present in respective XML, how I can impose the constraint?

                      <functionalView name="Learening_Purpose_VW" description="Learning Exercise">

                       

                      Thanks,

                      Rajneesh

                      • 8. Re: Is it possible to impose required constraint at value level?
                        odie_63

                        Rajneesh Shukla-Oracle wrote:

                         

                        One more observation, I can not impose - maxOccurs="1" minOccurs="1" with parent element <xs:element name="functionalView">

                        You don't need to.

                        It is implied that a top-level (root) element must occur once and only once in a given XML instance document.

                        1 person found this helpful