|
|
|
||||||||
![]() |
|
|
![]() |
CAUTION: This tutorial is under construction!!!
| Purpose | This tutorial is the part 2 of the SDF tutorials, it aims to help to learn to work with DRB APIŽ using SDF (Structured Data File) in some typical scenario. |
|---|---|
| Target audience | Intermediate |
| Required knowledge |
Before you continue you should have a basic understanding of the following:
|
| What you will learn in this tutorial | In this part 2 of SDF tutorial you will learn more about SDF usage in typical scenario. |
You may find usefull to configure your environnment by using an alias,
so that the command of this tutorial appears simpler.
The following definition is for Bash
shell:
alias drb='java -jar [DRB_INSTALLATION_HOME]/lib/java/drb-[M]-[m]-[t].jar'
Having the list.ascii
:
LIST_OF_NUMBERS=1 145 -56 101
Note: We know that the number of items in this sample is always 4.
Having the list.xsd
:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sdf="http://www.gael.fr/2005/04/drb/sdf"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<!-- Definition of the root node which contains all the content -->
<xs:element name="Lists">
<xs:complexType>
<xs:annotation>
<xs:appinfo>
<sdf:block>
<sdf:encoding>ASCII</sdf:encoding>
</sdf:block>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="ListOfNumbers" type="ListOfNumbersType">
<xs:annotation>
<xs:documentation xml:lang="en">
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="ListOfNumbersType">
<xs:annotation>
<xs:documentation xml:lang="en">
</xs:documentation>
<xs:appinfo>
<sdf:block>
<sdf:encoding>ASCII</sdf:encoding>
<sdf:padding type="header">16</sdf:padding>
<sdf:delimiter> </sdf:delimiter>
<sdf:array>
<sdf:occurrence>4</sdf:occurrence>
</sdf:array>
</sdf:block>
</xs:appinfo>
</xs:annotation>
<xs:list itemType="xs:integer"/>
</xs:simpleType>
</xs:schema>
The main point is the sdf:occurrence markup which
is set to the fixed value: "4", since there is always 4 items
in our data file.
In this particular case two situations can occurs:
list2.ascii
:
NB_NUMBERS=4 LIST_OF_NUMBERS=1 145 -56 101
Note that the first entry (NB_NUMBERS) in
the file indicate the number of values in the second field.
Having the list2.xsd
:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sdf="http://www.gael.fr/2005/04/drb/sdf"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<!-- Definition of the root node which contains all the content -->
<xs:element name="Lists">
<xs:complexType>
<xs:annotation>
<xs:appinfo>
<sdf:block>
<sdf:encoding>ASCII</sdf:encoding>
</sdf:block>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="NbNumbers" type="NbNumbersType">
<xs:annotation>
<xs:documentation xml:lang="en">
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="ListOfNumbers" type="ListOfNumbersType">
<xs:annotation>
<xs:documentation xml:lang="en">
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="NbNumbersType">
<xs:annotation>
<xs:documentation xml:lang="en">
</xs:documentation>
<xs:appinfo>
<sdf:block>
<sdf:encoding>ASCII</sdf:encoding>
<sdf:padding type="header">11</sdf:padding>
<sdf:delimiter> </sdf:delimiter>
</sdf:block>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:int"/>
</xs:simpleType>
<xs:simpleType name="ListOfNumbersType">
<xs:annotation>
<xs:documentation xml:lang="en">
</xs:documentation>
<xs:appinfo>
<sdf:block>
<sdf:encoding>ASCII</sdf:encoding>
<sdf:padding type="header">16</sdf:padding>
<sdf:delimiter> </sdf:delimiter>
<sdf:array>
<sdf:occurrence query="../NbNumbers"/>
</sdf:array>
</sdf:block>
</xs:appinfo>
</xs:annotation>
<xs:list itemType="xs:integer"/>
</xs:simpleType>
</xs:schema>
Note how the query ../NbNumbers specify inside the
sdf:occurrence markup is setted so that it
retrieve the value read from the first entry NbNumbers.
For accessing a xs:list remember to use the fn:data()
function.
Example:
drb -s "fn:data(list.ascii/(list.xsd)*/ListOfNumbers)[3]"
The previous command will return the third item in the list:
-56