users@jaxb.java.net

Re: XML Schema questions

From: Sriram Thyagarajan <Sriram_Thyagarajan_at_KEANE-NNE.com>
Date: Thu, 27 Mar 2003 10:54:27 -0500

Thanks for your reply.

My second question... Is is probably a simple question, because of my
limited exposure to XML schema...

Looks like XML schema defintion always looks for a root level node and then
within that node, sub nodes... e.g.

<XmlInterfaceRecord>
  <AccidentHeader>
    <VehicleInformation>
      <damageCodes>AB,CD</damageCodes>
      <damageAmount>200</damageAmount>
      <vin>AEBCDEFGHIJKLMNOPQRSTUV</vin>
      <vehicleMake>Toyota</vehicleMake>
      <vehicleYear>2002</vehicleYear>

      <RegistrationInformation>
      </RegistrationInformation>

      <RegistrationInformation>
      </RegistrationInformation>

    </VehicleInformation>
  </AccidentHeader>
  <AccidentHeader>
    <VehicleInformation>
      <damageCodes>AB,CD</damageCodes>
      <damageAmount>200</damageAmount>
      <vin>AEBCDEFGHIJKLMNOPQRSTUV</vin>
      <vehicleMake>Toyota</vehicleMake>
      <vehicleYear>2002</vehicleYear>

      <RegistrationInformation>
      </RegistrationInformation>

      <RegistrationInformation>
      </RegistrationInformation>

    </VehicleInformation>
  </AccidentHeader>
</XmlInterfaceRecord>

My current defintion....

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

  <xsd:element name="XmlInterfaceRecord" type="XmlInterfaceRecordType"/>

  <xsd:complexType name="XmlInterfaceRecordType">
    <xsd:sequence>
      <xsd:element name="AccidentHeader" type ="AccidentHeader"
      minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="AccidentHeader">
    <xsd:sequence>
      <xsd:element name="VehicleInformation" type="VehicleInfo"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="RegistrationInfo">
    <xsd:sequence>
      <xsd:element name="plateNumber" type="xsd:string"/>
      <xsd:element name="plateIssueState" type="xsd:string"/>
      <xsd:element name="registrationYear" type="xsd:decimal"/>
      </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="VehicleInfo">
    <xsd:sequence>
      <xsd:element name="vehicleMake" type="xsd:string"
        minOccurs="0" maxOccurs="1"/>
      <xsd:element name="vehicleYear" type="xsd:string"
        minOccurs="0" maxOccurs="1"/>
      <xsd:element name="vin" type="xsd:string"
        minOccurs="0" maxOccurs="1"/>
      <xsd:element name="damageCodes" type="xsd:string"
        minOccurs="0" maxOccurs="1"/>
      <xsd:element name="damageAmount" type="xsd:decimal"
        minOccurs="0" maxOccurs="1"/>
      <xsd:element name="RegistrationInformation" type="RegistrationInfo"
        minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
  </xsd:complexType>

</xsd:schema>

what I am looking for is a way to define multiple occurences like the
following ...

  <AccidentHeader>
    <VehicleInformation>
      <damageCodes>AB,CD</damageCodes>
      <damageAmount>200</damageAmount>
      <vin>AEBCDEFGHIJKLMNOPQRSTUV</vin>
      <vehicleMake>Toyota</vehicleMake>
      <vehicleYear>2002</vehicleYear>

      <RegistrationInformation>
      </RegistrationInformation>

      <RegistrationInformation>
      </RegistrationInformation>

    </VehicleInformation>
  </AccidentHeader>
  <AccidentHeader>
    <VehicleInformation>
      <damageCodes>AB,CD</damageCodes>
      <damageAmount>200</damageAmount>
      <vin>AEBCDEFGHIJKLMNOPQRSTUV</vin>
      <vehicleMake>Toyota</vehicleMake>
      <vehicleYear>2002</vehicleYear>

      <RegistrationInformation>
      </RegistrationInformation>

      <RegistrationInformation>
      </RegistrationInformation>

    </VehicleInformation>
  </AccidentHeader>

-----Original Message-----
From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
Sent: Wednesday, March 26, 2003 7:22 PM
To: JAXB-INTEREST_at_JAVA.SUN.COM
Subject: Re: XML Schema questions


> Is there a way to set the number of objects created, since some of my XML
> files can be very huge?

What you can do is to parse your document by a SAX parser, then from
your ContentHandler, once you hit <a>, you start forwarding SAX events
to JAXB. At </a>, you'll ask JAXB to give the object, and you can
process it, then throw it away.

Repeat this process until you process the entire document. This allows
you to just keep a small portion of data at any given time. And as a
result this is much more efficient.


> 2. Is there a way to specifiy the main node will be repeated? My following
> definition assumes there will be only one root element.
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>
> <xsd:element name="RootNode" type="XType"/>
>
> <xsd:complexType name="XType">
> <xsd:sequence>
> <xsd:element name="AccidentHeader" type ="AccidentHeaderType"
> minOccurs="0" maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> </xsd:schema>
>
> Is there a way to specify the file will have multiple AccidentHeader nodes
> (no RootNodelevel)

I'm sorry, I don't understand what you mean. Why you need multiple
AccidentHeader class? Is this related to your first question?



regards,
--
Kohsuke KAWAGUCHI                  408-276-7063 (x17063)
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com