|
|
|
||||||||
![]() |
|
|
![]() |
Important: READ FIRST!
General
Sources
Important notice:
For conveniency, in all the following, the drb word is an
alias equivalent to:
java -jar [DRB_INSTALLATION_HOME]/lib/java/drb-[M]-[m]-[t].jar
First you may be interested by the complete list of DRB supported XQuery functions:
drb --help xql
Then if you want a detailed help about a specific function (for example fn:concat()) you may use the command:
drb --help xql concat
Note: All the rest of this question talk about a binary file but the usage is the same for an ASCII file.
Usualy you may want to set a schema on binary file in order to be
able to process it with DRB API.
For this purpose, GAEL has develop a specific syntax:
binfile.dat/(binfile.xsd)ROOT_NODE_NAME/XPATH
Where:
binfile.dat: is the binary filename.binfile.xsd: is the XML Schema (with SDF tags)
corresponding to the binary file.ROOT_NODE_NAME: is the root node name (as describe by
the XML Schema).XPATH: is the XPath you may want to reach in the file.
For example having the file binfile.dat (hexadecimal dump of the binary file):
00000000 00 00 07 d8 00 47 00 41 00 45 00 4c |...?.G.A.E.L|
And having its corresponding XML Schema file binfile.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="File_Root">
<xs:complexType>
<xs:sequence>
<xs:element name="YEAR" type="YEARType">
<xs:annotation>
<xs:documentation xml:lang="en">
The current year.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="FIRM" type="FIRMType">
<xs:annotation>
<xs:documentation xml:lang="en">
Firm name.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="YEARType">
<xs:annotation>
<xs:appinfo>
<sdf:block>
<sdf:encoding>BINARY</sdf:encoding>
<sdf:length>4</sdf:length>
</sdf:block>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:int"/>
</xs:simpleType>
<xs:simpleType name="FIRMType">
<xs:annotation>
<xs:appinfo>
<sdf:block>
<sdf:encoding>BINARY</sdf:encoding>
</sdf:block>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:length value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
You may extract "YEAR" value from the binary file called
binfile.dat and
described by the XML Schema document called binfile.xsd
with the following command line:
drb --query 'fn:data(binfile.dat/(binfile.xsd)File_Root/YEAR)'
2008
Having the input XML file (animals.xml)
<animals> <animal>Tiger</animal> <animal>Cat</animal> <animal>Dog</animal> <animal>Frog</animal> <animal>Butterfly</animal> </animals>
If you make a query for extracting all the animal names:
drb --query 'fn:data(animals.xml/animals/animal)'
Then you get as output a sequence of items:
Tiger, Cat, Dog, Frog, Butterfly
In many cases you may have want to have this list of names to be put in your own XML structure, for example:
<myXMLStructure> <name>Tiger</name> <name>Cat</name> <name>Dog</name> <name>Frog</name> <name>Butterfly</name> </myXMLStructure>
For this to be achieve you have to modify your intial query like in the following:
drb --query '<myXMLStructure>{ for $animal in animals.xml/animals/animal return <name>{ fn:data($animal) }</name> }</myXMLStructure>'
For the official supported procedure, please see Handbook chapter "Getting Started"/"How to install DRB API"
to be completed soon...