RE: type in the XML instance

Hi,
Thankd Ed for u email..I think for me there would be no problem when i use

<getCustomerID xmlns="http://www.vordel.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="test.xsd">Error
</getCustomerID>
(without the xsi:type attribute)

the problem only occurs when I use with the xsi:type element ...
So in ur case if u use
<?xml version = "1.0"?>
   <CustomerId xsi:type="xsd:string">Ed</CustomerId>
  <CustomerId xsi:type="xsd:string">Jaikrishnan</CustomerId>
</EnumTest>
using this xml instead with ur schema it gives me the error
ception: cvc-elt.4.3: Type 'xsd:string' is not validly derived  from the
type definition of element 'CustomerId'


So I changed the schema to
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:element name="EnumTest">
  <xsd:complexType>
   <xsd:sequence>
    <!-- CustomerId repeats 1 or more times -->
    <xsd:element maxOccurs="unbounded" name="CustomerId">
     <xsd:simpleType>
         <xsd:restriction>
            <xsd:simpleType>
               <xsd:union memberTypes="xsd:string"/>
             </xsd:simpleType>
             <xsd:enumeration value="JK" />
             <xsd:enumeration value="DAVE" />
          </xsd:restriction>
      </xsd:simpleType>
    </xsd:element>
   </xsd:sequence>
  </xsd:complexType>
 </xsd:element>
</xsd:schema>

Now when u validate the xml it passes even if the value is wrong.
When i send the xml without the xsi:type it gives me the correct exception.
<?xml version = "1.0"?>
   <CustomerId >Ed</CustomerId>
  <CustomerId >Jaikrishnan</CustomerId>
</EnumTest>
So there seems to be some difference in how it is validated when there is
type attrbute
This is my problem..I hope some one can help me reg to this.
Thanks,
JK

-----Original Message-----
From: Wax, Ed [mailto:Ed_Wax@csgsystems.com]
Sent: 10 December 2004 17:47
To: Jaikrishnan Pillai
Subject: RE: type in the XML instance


  Jaikrishnan,

  If you want a schema to restrict the entry of a given element, here is one
way to go about it:
    <?xml version = "1.0" encoding = "UTF-8"?>
    <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
     <xsd:element name = "EnumTest">
      <xsd:complexType>
       <xsd:sequence>
        <!-- CustomerId repeats 1 or more times -->
        <xsd:element name = "CustomerId" maxOccurs = "unbounded">
         <xsd:simpleType>
          <xsd:restriction base = "xsd:string">
           <xsd:enumeration value = "DAVE"/>
           <xsd:enumeration value = "JK"/>
          </xsd:restriction>
         </xsd:simpleType>
        </xsd:element>
       </xsd:sequence>
      </xsd:complexType>
     </xsd:element>
    </xsd:schema>

  As far as the XML is concerned, here is a sample document that has valid
and invalid entries (I made the CustomerId a repeatable field for ease of
testing):
    <?xml version = "1.0"?>
    <EnumTest xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation = "EnumTest.xsd">
      <CustomerId>DAVE</CustomerId>
      <CustomerId>JK</CustomerId>
      <CustomerId>Ed</CustomerId>
      <CustomerId>Jaikrishnan</CustomerId>
    </EnumTest>

  Predictably, Xerces (I use v2.6.2) saw no problem with the first 2 entries
but did complain about the last 2:
    [Error] EnumTestInstance.xml:5:29: cvc-enumeration-valid: Value 'Ed' is
not facet-valid with respect to enumeration '[DAVE, JK]'. It must be a value
from the enumeration.
    [Error] EnumTestInstance.xml:5:29: cvc-type.3.1.3: The value 'Ed' of
element 'CustomerId' is not valid.
    [Error] EnumTestInstance.xml:6:38: cvc-enumeration-valid: Value
'Jaikrishnan' is not facet-valid with respect to enumeration '[DAVE, JK]'.
It must be a value from the enumeration.
    [Error] EnumTestInstance.xml:6:38: cvc-type.3.1.3: The value
'Jaikrishnan' of element 'CustomerId' is not valid.
  Hope that helps.

  Regards,
  Ed
    -----Original Message-----
    From: Jaikrishnan Pillai [mailto:jaikrishnan.pillai@vordel.com]
    Sent: Thursday, December 09, 2004 10:26 AM
    To: xerces-j-user@xml.apache.org
    Subject: xsi:type in the XML instance


    Hi ,
    I am trying to do a schema validation using Xerces(version 2.2.1).The
xml I have is

    <getCustomerID xmlns="http://www.vordel.com/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xsi:schemaLocation="http://www.vordel.com/
file:///E:/TMobile/samplemessages/new/test/tony/test.xsd"
    xsi:type="xsd:string">Error
    </getCustomerID>


    and the schema I have is

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema targetNamespace="http://www.vordel.com/"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:tns="http://www.vordel.com/">

    <xsd:element name="getCustomerID">
         <xsd:simpleType>
            <xsd:restriction>
                       <xsd:simpleType>
                         <xsd:union memberTypes="xsd:string"/>
                       </xsd:simpleType>
                       <xsd:enumeration value="JK" />
                       <xsd:enumeration value="DAVE" />
            </xsd:restriction>
          </xsd:simpleType>
    </xsd:element>

    <xsd:simpleType name="derived_string">
       <xsd:restriction base="xsd:string">
         <xsd:enumeration value="JK" />
         <xsd:enumeration value="DAVE" />
       </xsd:restriction>
    </xsd:simpleType>
    </xsd:schema>

    Now what i want my schema to achieve is to restrict the value to either
"DAVE" or "JK".Also note the xsi:type attrbute in the schema.
    Even if the value is different I am still able to validate the schema.
Is this the expected beahaviour?

    Now if I take away the xsi:type="xsd:string" from the xml.Then it will
try to validate the content and gives me the correct exception.
    Now I need to have  type attribute as the Web service rquires it.So I
want to build up a schema for the same.

    I changed the schema to use <xsd:union
memberTypes="tns:derived_string"/>
    then it gives me a error
    org.xml.sax.SAXParseException: cvc-elt.4.3: Type 'xsd:string' is not
validly derived from the type definition of element 'getCustomerID'.

    Can someone help me out.I want to know how does schema validation differ
when there is xsi:type attribute in xml itself.

    Thanks,
    JK

Received on Monday, 13 December 2004 14:06:13 UTC