You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Sridhar Raju Y <sr...@infy.com> on 2001/11/21 06:03:13 UTC

Facing problem...

Hi All,
  I am having XSD file like this.

MyXSD.XSD


<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:import namespace="http://www.w3.org/2001/XMLSchema"
schemaLocation="http://www.w3.org/2001/XMLSchema
file:///c:/XMLSchema.xsd"/>

    <xsd:element name="message">
        <xsd:annotation>
            <xsd:documentation xml:lang="en">
        Message definition
      </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:choice minOccurs="0" maxOccurs="unbounded">
                    <xsd:element ref="xsd:element"/>
                    <xsd:element ref="xsd:complexType"/>
                </xsd:choice>
            </xsd:sequence>
            <xsd:attribute name="name" type="name" use="required"/>
            <xsd:attribute name="type" type="messageType"
default="data"/>
        </xsd:complexType>
    </xsd:element>

.....
.....

</xsd:schema>


And my instance doc looks like this.

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

<package namespace="http://mycommerce.com"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation='MyXSD.xsd'
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         >

<message name="xxx" type="req">
<xsd:element name="custid" type="string"/>
</message>
</package>


While parsing this document it is asking to define xsd:element in the
XSD file..
Actually I had refered xsd:element in the XSD.

what could be the reason.

And one more thing In schema file I am using import to refer the
XMLSchema.My program is trying to open the internet connection.If I
remove import it is not opening the connection.

I want to use import in schema with out opening the internet
connection....

Any pointer in this regard will be great.......

Thanks,
Sridhar.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


RE: Facing problem...

Posted by Craig Collings <cr...@cabusiness.co.nz>.
In the schema that you outlined thus;
    <xsd:element name="message">
        <xsd:annotation>
            <xsd:documentation xml:lang="en">
        Message definition
      </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:choice minOccurs="0" maxOccurs="unbounded">
                    <xsd:element ref="xsd:element"/><!-- XXX Invalid -->
                    <xsd:element ref="xsd:complexType"/><!-- XXX Invalid -->
                </xsd:choice>
            </xsd:sequence>
            <xsd:attribute name="name" type="name" use="required"/>
            <xsd:attribute name="type" type="messageType"
default="data"/>
        </xsd:complexType>
    </xsd:element>

ref is used to refer to an element which you have defined in this schema,
like this
<xsd:schema>
	<xsd:element name="message" minOccurs="0" maxOccurs="unbounded">
		<xsd:complexType>
            	<xsd:sequence>
                		<xsd:choice>
                    		<xsd:element ref="TextMessage"/>
                    		<xsd:element ref="BinaryMessage"/>
                		</xsd:choice>
            	</xsd:sequence>
            <xsd:attribute name="name" type="name" use="required"/>
            <xsd:attribute name="type" type="messageType" default="data"/>
        	</xsd:complexType>
	</xsd:element>

	<xsd:element name="TextMessage" type="xsd:anyType"/>
	<xsd:element name="BinaryMessage" type="xsd:anyType"/>
</xsd:schema>

Note too, that the elements referred to must be direct children of the
schema
See XML Schema Part 0: Primer from http://www.w3.org/TR/xmlschema-0/

Some other observations.
I'm not sure that you can or would want to apply occurrence constraints to
choice groups. I've moved those restraints to the message element. But I'm
not sure that is what you intended.
You will remember that the types assigned to the element attributes must be
simple types not complex types (derived from other w3c simple types).
The other thing - Instead of using ref (which is just shorthand) you could
just assign types as usual. eg

	<xsd:choice>
      	<xsd:element ref="TextMessageType"/>
            <xsd:element ref="BinaryMessageType"/>
      </xsd:choice>
These types could be defined anywhere.

hope that helps, :)

-----Original Message-----
From: Sridhar Raju Y [mailto:sridhar_y@infy.com]
Sent: Wednesday, 21 November 2001 6:03 p.m.
To: xerces-j-user@xml.apache.org
Subject: Facing problem...


Hi All,
  I am having XSD file like this.

MyXSD.XSD


<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:import namespace="http://www.w3.org/2001/XMLSchema"
schemaLocation="http://www.w3.org/2001/XMLSchema
file:///c:/XMLSchema.xsd"/>

    <xsd:element name="message">
        <xsd:annotation>
            <xsd:documentation xml:lang="en">
        Message definition
      </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:choice minOccurs="0" maxOccurs="unbounded">
                    <xsd:element ref="xsd:element"/>
                    <xsd:element ref="xsd:complexType"/>
                </xsd:choice>
            </xsd:sequence>
            <xsd:attribute name="name" type="name" use="required"/>
            <xsd:attribute name="type" type="messageType"
default="data"/>
        </xsd:complexType>
    </xsd:element>

.....
.....

</xsd:schema>


And my instance doc looks like this.

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

<package namespace="http://mycommerce.com"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation='MyXSD.xsd'
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         >

<message name="xxx" type="req">
<xsd:element name="custid" type="string"/>
</message>
</package>


While parsing this document it is asking to define xsd:element in the
XSD file..
Actually I had refered xsd:element in the XSD.

what could be the reason.

And one more thing In schema file I am using import to refer the
XMLSchema.My program is trying to open the internet connection.If I
remove import it is not opening the connection.

I want to use import in schema with out opening the internet
connection....

Any pointer in this regard will be great.......

Thanks,
Sridhar.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org