| MAP | SASAX Documents > Parsing with SASAX > Composite element | << | >> | 
This section explains how to parse composite element consisting of other elements with SASAX.
Schema in XML Schema and sample of document is shown in "Document structure".
Schema in XML Schema:
<xs:schema 
  targetNamespace="http://www.lares.dti.ne.jp/~foozy/"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:local="http://www.lares.dti.ne.jp/~foozy/">
  <xs:simpleType name="int">
    <xs:restriction base="xs:integer"/>
  </xs:simpleType>
  <xs:simpleType name="string">
    <xs:restriction base="xs:token"/>
  </xs:simpleType>
  <xs:element name="composite">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="int" type="local:int"
          form="qualified"/>
        <xs:element name="string" type="local:string"
          minOccurs="0"
          form="qualified"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
Sample:
<foozy:composite
 xmlns:foozy="http://www.lares.dti.ne.jp/~foozy/">
  <foozy:int>
    12245678
  </foozy:int>
  <foozy:string>
    optional text message
  </foozy:string>
</foozy:composite>
You can know below things about target document.
Objects to parse the document described in the former are created as shown in "Element object(s) creation".
String uri = "http://www.lares.dti.ne.jp/~foozy/"; CompositeElement compositeElement = new CompositeElement(null, uri, "composite"); IntElement intElement = new IntElement(compositeElement, uri, "int"); composite.addMustItem(intElement); StringElement stringElement = new StringElement(compositeElement, uri, "string"); composite.addOptionalItem(stringElement);
After creation of elements belonging to "composite",
they are registered to "composite".
The difference of registration method
(addMustItem and addOptionalItem)
is the difference of element necessity.
NOTE:
Many of unexpected behaviors around CompositeElement are
caused by missing invocation of addMustItem
(or addOptionalItem).
Please check whether they are invoked or not.
You can parse XML document by the code shown in "Parse document" as you know.
ElementDrivenHandler handler = new ElementDrivenHandler(compositeElement); handler.parse(reader);
After
ElementDrivenHandler#parse invocation,
you can (may) get integer (string) value from 
"intElement" ("stringElement") by getInteger method
of IntElement
(getString of
StringElement).
For detail about parameter of that method,
please see "Custom element",
or API document.
Complete code for this tutorial section is
jp.ne.dti.lares.foozy.sasax.CompositeDemo
under src/demo/sasax/src in distribution.
This class is included in demo.jar of binary distribution.
Class diagram in this section is shown below:
Object diagram in this section is shown below:
Processing flow between ElementDrivenHandler, CompositeElement and Element implementation class is shown as below:
And sequence diagram is shown below.
In this tutorial, abbreviated class names are used. Complete names are shown below.
| Notation | Full name | 
|---|---|
| CompositeElement | jp.ne.dti.lares.foozy.sasax.CompositeElement | 
| ElementDrivenHandler | jp.ne.dti.lares.foozy.sasax.ElementDrivenHandler | 
| IntElement | jp.ne.dti.lares.foozy.sasax.IntElement | 
| StringElement | jp.ne.dti.lares.foozy.sasax.StringElement | 
| MAP | SASAX Documents > Parsing with SASAX > Composite element | << | >> |