Thanks, for your reply!

That's what I thought, but trying out an example did not work out as
expected. The parser did not seem to bother with a xsd:float as a 'Yuri' in
param1 (if I coment out param2 and param3 it parses without problems) and it
seems to be mixing the float declared in param1 with the Item in param2.

SOURCE CODE:
------------
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setNamespaceAware(true);
      dbf.setValidating(true);
      DocumentBuilder db = dbf.newDocumentBuilder();

      Document doc = db.parse(new File("test.xml"));

RESULT:
-------
Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
set, which is probably not what is desired.  Parser will use a default
ErrorHandler to print the first 10 errors.  Please call
the 'setErrorHandler' method to fix this.
Error: URI=file:e:/source/java/test.xml Line=15: Datatype error: In element
'my:Item' : my item is not a float.
----------------------------------------------------------------------------
-----------

TEST.XML
----------------------------------------------------------------------------
-----------
<?xml version="1.0"?>
<base:OPERATION
    xmlns:base="urn:base"
    xmlns:my="urn:myschema"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
    xsi:schemaLocation="urn:base base.xsd urn:myschema myschema.xsd">

    <base:PARAMETER name="myParam1">
        <base:VALUE xsi:type="xsd:float">Yuri</base:VALUE>
    </base:PARAMETER>
    
    <base:PARAMETER name="myParam2">
        <base:VALUE xsi:type="my:PurchaseOrderType">
                <my:Item>my item</my:Item>
        </base:VALUE>
    </base:PARAMETER>

    <base:PARAMETER name="myParam3">
        <my:PurchaseOrder>
                <my:Item>my item</my:Item>
        </my:PurchaseOrder>
         </base:PARAMETER>
</base:OPERATION>
----------------------------------------------------------------------------
-----------

BASE.XSD
----------------------------------------------------------------------------
-----------
<?xml version = "1.0" encoding = "UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema";
            targetNamespace="urn:base"
            xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
            elementFormDefault="qualified">

    <element name = "OPERATION">
        <complexType>
            <sequence>
                <element name="PARAMETER" minOccurs="0"
maxOccurs="unbounded">
                        <complexType>
                                <choice>
                                        <element name="VALUE"/>
                                        <any/>
                                </choice>
                                <attribute name = "name" use = "required"
type = "Name"/>
                            </complexType>
                </element>
            </sequence>
        </complexType>
    </element>
</schema>
----------------------------------------------------------------------------
-----------
MYSCHEMA.XSD
----------------------------------------------------------------------------
-----------
<?xml version = "1.0" encoding = "UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema";
                        xmlns:tns="urn:myschema"
            targetNamespace="urn:myschema"
            xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                                elementFormDefault="qualified">

          <complexType name="PurchaseOrderType">
                        <sequence>
                                 <element name="Item" type="string"/>
                        </sequence>
          </complexType>
          
    <element name = "PurchaseOrder" type="tns:PurchaseOrderType"/>

</schema>
----------------------------------------------------------------------------
-----------

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 20, 2002 15:09
To: [EMAIL PROTECTED]
Subject: Re: xsi:type and validation of polymorphic types in XML
instances


You mean validate "Me" against type "float"? Sure Xerces does that. This is
the reason why xsi:type exists.

I suspect that you meant xsi:type="xsd:float", where xsd is bound to the
schema namespace.

Sandy Gao
Software Developer, IBM Canada
(1-905) 413-3255
[EMAIL PROTECTED]



 

                    Yuri de Wit

                    <yuri.dewit@metas       To:
"'[EMAIL PROTECTED]'"                              
                    erver.com>               <[EMAIL PROTECTED]>

                                            cc:

                    02/20/2002 02:34        Subject:     xsi:type and
validation of polymorphic types in XML     
                    PM                       instances

                    Please respond to

                    xerces-j-dev

 

 




Can Xerces validate types, as opposed to elements and attributes, in XML
instances?

...
<parameter name="param1">
           <default-value xsi:type="float">Me</default-value>
</parameter>
...

Lets say the schema has something like this:

...
<xsd:element name="parameter">
           <xsd:complexType>
                     <xsd:sequence>
                               <xsd:element name="default-value"
type="xsd:anyType"/>
                     </xsd:sequence>
           </xsd:complexType>
</xsd:element>
....

WILL XERCES VALIDATE <default-value> CONTENT? I need a way to validate
parameter default values being them simple types or complex types in my XML
instance that is not known in the schema at design time.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to