You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Ralph Gauges <ra...@eml.villa-bosch.de> on 2000/08/25 08:53:17 UTC

recursive complex types

Hi,

I have been playing around with XMLSchema and xerces-j for
serveral days and I have encountered a problem that I can
not solve (this is not the first time something like this
happens to me (-;).
I tried to define an XMLSchema that contains a recursive
datatype (kind like a directory tree where a directory can
have files and subdirectories and so on).
First I tried to implement this directly by defining a
complexType named NodeType that han an element Name which
was a string and an element Node which was of type NodeType.
Since this always lead to an error when I tried to validate
(just running SAX2Count with switches -n -v -s over it), I
tried it in a more indirect way. I defined a NodeList that
contains an element Node of NodeType and Node again conteins
a NodeList, but this leads to errors as well.
I will include a short example of my Schema and a sample
instance file that produces the error. Maybe somebody in
this mailinglist can tell me wether I am out of the specs
for schemas or if I did something very stupid in my schema
or the instance or if this could even be a bug in xerces. I
am truely sorry if this is a stupid request, but I just
can't see what I am doing wrong.
Thanks a lot

Ralph

"Test.xsd"

<schema>

 <element name="Tree" type="Tree"/>

 <complexType name="Tree">
   <element name="Nodes" type="NodeList" minOccurs="1"/>
 </complexType>

 <complexType name="NodeList">
   <element name="Node" type="JavaNode" minOccurs="1"
maxOccurs="unbounded"/>
 </complexType>

 <complexType name="JavaNode">
   <element name="Name" type="string" minOccurs="1"/>
   <element name="Type" type="string" minOccurs="0"/>
   <element name="Nodes" type="NodeList" minOccurs="0"/>
 </complexType>

</schema>


SimpleTest.xml

<?xml version="1.0"?>

  <Tree     
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="Test.xsd" >
    <Nodes>
       <Node>
         <Name>Test</Name>
         <Type>Test2</Type>
       </Node>
       <Node>
         <Name>Test1</Name>
         <Type>Hallo</Type>
         <Nodes>
           <Node>
             <Name>Hallo3</Name>
           </Node>
         </Nodes>
       </Node>
     </Nodes>
  </Tree>


Erromessage from IBM-JDK 1.3/Linux and xerces-j-1.1.3:


java -classpath $CLASSPATH:./xercesSamples.jar
sax.SAX2Count  -n -s -v ./SimpleTest.xml
c =110
c =115
c =118
[Error] SimpleTest.xml:18:16: The content of element type
"Node" must match "(Name,Type?,Nodes?)".
./SimpleTest.xml: 799 ms (11 elems, 1 attrs, 144 spaces, 25
chars)

Re: recursive complex types

Posted by Ralph Gauges <ra...@eml.villa-bosch.de>.
Eric Ye wrote:
> 
> Are you sure it is Xerces-J-1.1.3 ? I just tried your example, it didn't
> issue any errors.  Could it be possible your $CLASSPATH have an old version
> Xerces.jar that was put before the latest Xerces.jar.?
> 
> Eric Ye
> IBM JTC-Silicon Valley
> 

Oops, you saved my day. It wasn't the xerces that caused the
error, it was the ibm xml4j that was in the classpath.
Thank you very much.

Ralph

Re: recursive complex types

Posted by Eric Ye <er...@locus.apache.org>.
Are you sure it is Xerces-J-1.1.3 ? I just tried your example, it didn't
issue any errors.  Could it be possible your $CLASSPATH have an old version
Xerces.jar that was put before the latest Xerces.jar.?

Eric Ye
IBM JTC-Silicon Valley

----- Original Message -----
From: "Ralph Gauges" <ra...@eml.villa-bosch.de>
To: <xe...@xml.apache.org>
Sent: Thursday, August 24, 2000 11:53 PM
Subject: recursive complex types


> Hi,
>
> I have been playing around with XMLSchema and xerces-j for
> serveral days and I have encountered a problem that I can
> not solve (this is not the first time something like this
> happens to me (-;).
> I tried to define an XMLSchema that contains a recursive
> datatype (kind like a directory tree where a directory can
> have files and subdirectories and so on).
> First I tried to implement this directly by defining a
> complexType named NodeType that han an element Name which
> was a string and an element Node which was of type NodeType.
> Since this always lead to an error when I tried to validate
> (just running SAX2Count with switches -n -v -s over it), I
> tried it in a more indirect way. I defined a NodeList that
> contains an element Node of NodeType and Node again conteins
> a NodeList, but this leads to errors as well.
> I will include a short example of my Schema and a sample
> instance file that produces the error. Maybe somebody in
> this mailinglist can tell me wether I am out of the specs
> for schemas or if I did something very stupid in my schema
> or the instance or if this could even be a bug in xerces. I
> am truely sorry if this is a stupid request, but I just
> can't see what I am doing wrong.
> Thanks a lot
>
> Ralph
>
> "Test.xsd"
>
> <schema>
>
>  <element name="Tree" type="Tree"/>
>
>  <complexType name="Tree">
>    <element name="Nodes" type="NodeList" minOccurs="1"/>
>  </complexType>
>
>  <complexType name="NodeList">
>    <element name="Node" type="JavaNode" minOccurs="1"
> maxOccurs="unbounded"/>
>  </complexType>
>
>  <complexType name="JavaNode">
>    <element name="Name" type="string" minOccurs="1"/>
>    <element name="Type" type="string" minOccurs="0"/>
>    <element name="Nodes" type="NodeList" minOccurs="0"/>
>  </complexType>
>
> </schema>
>
>
> SimpleTest.xml
>
> <?xml version="1.0"?>
>
>   <Tree
> xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
>              xsi:noNamespaceSchemaLocation="Test.xsd" >
>     <Nodes>
>        <Node>
>          <Name>Test</Name>
>          <Type>Test2</Type>
>        </Node>
>        <Node>
>          <Name>Test1</Name>
>          <Type>Hallo</Type>
>          <Nodes>
>            <Node>
>              <Name>Hallo3</Name>
>            </Node>
>          </Nodes>
>        </Node>
>      </Nodes>
>   </Tree>
>
>
> Erromessage from IBM-JDK 1.3/Linux and xerces-j-1.1.3:
>
>
> java -classpath $CLASSPATH:./xercesSamples.jar
> sax.SAX2Count  -n -s -v ./SimpleTest.xml
> c =110
> c =115
> c =118
> [Error] SimpleTest.xml:18:16: The content of element type
> "Node" must match "(Name,Type?,Nodes?)".
> ./SimpleTest.xml: 799 ms (11 elems, 1 attrs, 144 spaces, 25
> chars)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>