Professional Documents
Culture Documents
2
COPYRIGHT 1994- 2003 SoftVelocity Incorporated. All rights reserved.
This publication is protected by copyright and all rights are reserved by SoftVelocity Incorporated.
It may not, in whole or part, be copied, photocopied, reproduced, translated, or reduced to any
electronic medium or machine-readable form without prior consent, in writing, from SoftVelocity
Incorporated.
This publication supports Clarion. It is possible that it may contain technical or typographical
errors. SoftVelocity Incorporated provides this publication as is, without warranty of any kind,
either expressed or implied.
SoftVelocity Incorporated
2335 East Atlantic Blvd.
Suite 410
Pompano Beach, Florida 33062
(954) 785-4555
www.softvelocity.com
Second Edition
Trademark Acknowledgements:
SoftVelocity is a trademark of SoftVelocity Incorporated.
Clarion is a trademark of SoftVelocity Incorporated.
Microsoft, Windows, and Visual Basic are registered trademarks of Microsoft Corporation.
All other products and company names are trademarks of their respective owners.
Contents:
Introduction.......................................................................................................................................6
Document Overview ....................................................................................................................6
General Description .....................................................................................................................6
Common Terms ...........................................................................................................................6
Additional References..................................................................................................................6
Support API Implementation ............................................................................................................7
OOP Clarion/XML Extension............................................................................................................8
Introduction ..................................................................................................................................8
Purpose........................................................................................................................................8
The Clarion XML Class Model .....................................................................................................8
Import/Export Class Overview.................................................................................................8
Class Diagram ...........................................................................................................................10
XML Structure Styles .................................................................................................................11
Conceptual Example .............................................................................................................12
Technical Reference ......................................................................................................................15
Class based XML support..........................................................................................................15
StructWrapper .......................................................................................................................15
XMLNameMap.......................................................................................................................15
XMLExchange .......................................................................................................................15
XMLNavigator........................................................................................................................15
StructWrapper Base Methods....................................................................................................16
getFieldsCount ......................................................................................................................16
getFieldValueByIndex............................................................................................................16
setFieldValueByIndex............................................................................................................17
getFieldValueByName...........................................................................................................17
getFieldValueByXMLName ...................................................................................................17
setFieldValueByName ...........................................................................................................18
setFieldValueByXMLName ...................................................................................................18
getFieldLabel .........................................................................................................................18
getXMLFieldLabel..................................................................................................................19
getFieldType..........................................................................................................................19
getFieldSize...........................................................................................................................19
getCapacity............................................................................................................................19
startIterate .............................................................................................................................20
getNextRow ...........................................................................................................................20
clearBuffer .............................................................................................................................20
addRow .................................................................................................................................20
setNameMap .........................................................................................................................21
getNameMap .........................................................................................................................21
isMappingEnabled .................................................................................................................21
setMappingEnabled...............................................................................................................21
StructWrapper Hierarchical support methods............................................................................22
getFirstChild ..........................................................................................................................22
getParent ...............................................................................................................................22
getNextSibling .......................................................................................................................22
updateRowPos ......................................................................................................................22
5
Clarion XML Support Reference Guide
FromXMLFile .........................................................................................................................40
GetLastError ..........................................................................................................................40
Template Support (optional) ......................................................................................................43
Built-in Caveats and Limitations ................................................................................................44
List of XML Support Functions...................................................................................................45
Parameter list for listed functions: .........................................................................................46
Function Error codes .............................................................................................................47
Introduction
Document Overview
This document provides a description of the functionality of the Clarion/XML extension API. The
functionality describes both a procedure-based API and the more advanced functionality of the
Object Oriented API.
General Description
The Clarion XML support encapsulates a standard XML parser interface and provides
easy to use import/export related API functions and classes. The XML support utilizes the
CenterPoint XML C++ class library for reading and writing XML documents using DOM
(Document Object Model) Level 1 and Level 2 conforming interfaces. CenterPoint XML is based
on expat (the well-known XML Parser Toolkit).
There are three entry points provided so that the developer can work with XML data at different
levels:
1. Work directly with the DOM methods prototyped in cpxml.inc
2. Use the Procedure based API
o
The classes encapsulate all the functionality of the Procedure based API, and
also provide extended functionality.
Common Terms
DOM Document Object Model (in this document document object model used by XML parser)
XML eXtensible Markup Language
API Application Programming Interface
Additional References
For more information regarding DOM and XML, visit HTTP://www.w3.org for the latest Level 1
and Level 2 DOM specifications.
The template support automatically includes these project defines, but you will need to add this
manually for any hand coded projects.
Purpose
The main purpose of providing a class oriented API is to provide additional functionality and
control for the import and export of data from the users application. Class objects as a data type
having state provide a user-friendlier environment to support not only predefined import and
export scenarios, but also custom usage.
A name mapping facility, which provides the possibility to define formatting information
with Clarions picture token. The developer can also override the standard formatting
behavior by specifying a user-defined formatting method in the XMLNameMap class. The
Procedure-based API also supports this functionality.
When the Clarion/XML Classes are used, the DOM Document object is hidden inside
XMLExchange class, so its not the users responsibility to release the Document object.
The TreeViewWrapper class provides export for a VIEW structure with several nested
JOINs into XML with tree-like hierarchical structure.
XMLSchemas
Future versions will also contain an XMLSchema class to support XML schema related
operations
10
Class Diagram
The following diagram illustrates the relations between the main classes and also shows the main
methods signatures:
11
The data structure is represented as a sequence of XML elements, and corresponds to the
records of the exported structure enclosed in a tag.
For example, for the attribute-based style, a structure can look like this:
<data>
<row lastname="Wright" firstname="Carl" phone="2221697"/>
<row lastname="Curry" firstname="Charmaine" phone="3339716"/>
</data>
12
Conceptual Example
The following example is implemented with the set of import/export classes and demonstrates the
formatting feature.
Consider the following XML files:
Customer.XML (Contains customer information)
<?xml version="1.0"?>
<data>
<row lastname="Wright" firstname="Carl" phone="2221697"/>
<row lastname="Curry" firstname="Charmaine" phone="3339716"/>
</data>
BYTE
!temporary flag
Customer
LastName
Phone
QUEUE
STRING(30)
STRING(30)
END
nameMap
xExch
qWrp
XMLNameMap
XMLExchange
QueueWrapper
CODE
!Import data from file Customer.xml to Customer QUEUE.
!Destination QUEUE contains only LastName, Phone fields so only data for
!these fields are imported
CC = xExch.open('Customer.XML')
IF CC
!Initialize the wrapper object
qWrp.init(Customer)
!put the data into QUEUE
xExch.fromXML(qWrp)
!Export data from Customer QUEUE to a file with name mapping and
!formatting
! Load name mapping information from NAMEMAP.XML
CC = nameMap.load('NameMap.XML')
if (cc)
qWrp.setNameMap(nameMap)
!attach name mapping information
xExch.close
!clear the object
xExch.create
!create new XML document
xExch.toXML(qWrp)
!put data from Customer to XML
cc = xExch.saveAs('CustomerData.XML')!save XML doc to file
if(NOT cc)
stop('Exporting error')
end
else
stop('NameMap.XML importing error')
end
else
stop('Customer.XML importing error')
end
13
15
Technical Reference
This section will cover in detail the four XML support base classes.
StructWrapper
A base class for handling complex Clarion data types. Its methods provide for accessing
fields of a Clarion structure at run-time and provide additional information about fields such as
a fields name and type. Also, the class may have reference to an XMLNameMap object to
make available the mapping of Clarion field names to XML names, and for user defined
processing of imported/exported values.
The class is a base class for the following wrapper classes: GroupWrapper,
QueueWrapper, FileWrapper, ViewWrapper (TreeViewWrapper). A developer will not use
this class directly. Only the derived type-specific classes are used at the user level. So, for
each data type you need to export/import, create the associated wrapper class for that
Clarion structure.
XMLNameMap
An auxiliary class to simplify work with name mapping structures. It contains an underlying
queue with name mapping and formatting information. It also allows you to specify userspecific custom data formatting functionality.
XMLExchange
Encapsulates import/export specific functionality. It uses the StructWrapper methods for
accessing individual fields to export or import values to/from XML. XMLExchange provides
additional methods to customize the import/export process.
XMLNavigator
An auxiliary class that allows you to navigate through XML DOM Document stored in
XMLExchange object.
16
getFieldsCount
getFieldsCount( ), SIGNED
The getFieldsCount method returns the number of fields in the Clarions structure available for
import export. In case that mapping is enabled, this number can be less than actual number of
the fields in the structure.
ReturnValue: SIGNED
getFieldValueByIndex
getFieldValueByIndex(unsigned index), string
index
The field index. If mapping is enabled, only mapped fields are counted.
The getFieldValueByIndex method returns the field value as a string by specified index. The
returned value is the result of the transformation defined in the mapping (if enabled), or the
default conversion to a string.
ReturnValue: STRING
17
setFieldValueByIndex
setFieldValueByIndex(unsigned index, string value), unsigned
index
The field index to set. If mapping is enabled, only mapped fields are counted.
value
getFieldValueByName
getFieldValueByName(string field),string
field
The getFieldValueByName method returns the field value as a string from the specified field
name. The value returned is a result of transformation defined in the mapping (if enabled), or by
default conversion to string. An empty string is returned in case there is no field corresponding to
the specified field name.
Return Value: STRING
getFieldValueByXMLName
getFieldValueByXMLName(string field),string
field
The getFieldValueByXMLName method returns the field value as a string from the specified
field name. The returned value is result of transformation defined in the mapping (if enabled),
otherwise default conversion to string is applied. An empty string is returned in case there is no
field corresponding to specified field name.
Return Value: STRING
18
setFieldValueByName
setFieldValueByName(string field,string value), unsigned
field
value
The setFieldValueByName method returns CPXMLErr:NoError if the value has been set, or
CPXMLErr:FieldNotFound otherwise. If mapping is enabled, only mapped fields are processed.
Return Value: UNSIGNED
setFieldValueByXMLName
setFieldValueByXMLName(string field,string value), unsigned
field
value
getFieldLabel
getFieldLabel(unsigned cou),string
cou
The getFieldLabel method returns the Clarion label of the field identified by the fields index cou
value.
Return Value: STRING
19
getXMLFieldLabel
getXMLFieldLabel(unsigned cou),string
cou
getFieldType
getFieldType(unsigned cou),unsigned
The getFieldType method is necessary to produce XML schema. (Not implemented in this
version)
Return Value: UNSIGNED
getFieldSize
getFieldSize(UNSIGNED cou, *unsigned size, *unsigned precision)
The getFieldSize method gets the size of the field (for STRINGS, DECIMAL, etc.). (Not
implemented in this version)
Return Value: BYTE
getCapacity
getCapacity( ), unsigned
The getCapacity method returns the maximum possible number of rows (capacity) in the
corresponding Clarion structure. For example, a GROUP will return 1, and a QUEUE will return -1
(infinite).
Return Value: UNSIGNED
20
startIterate
startIterate( )
The startIterate method sets the inner current row counter to its initial state (the beginning of the
rows sequence). This method should be called before the getNextRow method.
getNextRow
getNextRow( )
The getNextRow method gets the next row (record). If successful, getNextRow returns
CPXMLErr:NoError. If not successful, one of the following errors can be returned:
CPXMLErr:EOF
CPXMLErr:IllegalFunctionCall
Return Value: BYTE
clearBuffer
clearBuffer( )
addRow
addRow( )
The addRow method adds a new row to the Clarion structure. If successful, addRow returns
CPXMLErr:NoError. Otherwise, addRow returns CPXMLErr:InternalError.
Return Value: BYTE
setNameMap
setNameMap(XMLNameMap map)
setNameMap(MapQueue map)
map
The setNameMap methods set name mapping structures that are used on export/import
operations. If successful, setnameMap returns CPXMLErr:NoError.
Return Value: BYTE
getNameMap
getNameMap( ),*XMLNameMap
The getNameMap method returns the pointer to the inner XMLNameMap object.
isMappingEnabled
isMappingEnabled( )
setMappingEnabled
setMappingEnabled(byte flag=true)
flag
21
22
getFirstChild
getFirstChild( ),*StructWrapper
The getFirstChild method returns the reference to the first child node.
getParent
getParent( ),*StructWrapper
getNextSibling
getNextSibling( ),*StructWrapper
The getNextSibling method returns the reference to the next sibling node.
updateRowPos
updateRowPos( )
The updateRowPos method stores the inner position value to the position of current row.
isRowPosChanged
isRowPosChanged( )
The isRowPosChanged method tests if the row position was changed since the last call of the
updateRowPos method.
Return Value: BYTE
23
Init
Init(*<type> clastr , removePrefix=true),byte
clastr
removePrefix
24
load
load(MapQueue map),byte
map
The load method loads mapping and formatting information. If successful, load returns
CPXMLErr:NoError. Otherwise, load returns CPXMLErr:InvalidArgument.
Return Value: BYTE
addRecord
addRecord(string clarionName, string xmlName, string picture),byte
clarionName
xmlName
picture
The addRecord method adds a new record with name mapping and formatting information. If
successful, addRecord returns TRUE. Otherwise, addRecord returns FALSE.
Return Value: BYTE
25
26
The following XMLNameMap methods are used by StructWrapper class to support name
mapping/formatting.
translateName
translateName(string name, byte toXML=true)
name
toXML
If set to TRUE then translate to XML name; otherwise translate to Clarion name
formatValue
formatValue(string name, string value, byte toXML=true)
name
value
toXML
The formatValue method formats a value to and from the XML form. It returns the string result of
the formatting.
The standard behavior of the function is to apply formatting according to the Picture in the
MappingQueue. You can override the default behavior with your own function.
Return Value: STRING
27
XMLExchange Class
The XMLExchange class provides main functionality for export/import. It contains an inner DOM
Document object that is used as intermediate storage for exported/imported data. You can load
data in the Document object from a StructWrapper object, or put data from the Document object
to a StructWrapper object. This class supports methods to save data to a XML file and to load
data from an XML file. Also, you can set/get a number of export/import parameters.
open
open(string path)
path
The open method opens an XML file. The method returns CPXMLErr:NoError if successful, or
CPXMLErr:XMLReadFail if not successful.
Return Value: BYTE
createXML
createXML(<string schemaURL>)
schemaURL
28
close
close( )
The close method closes access to XML DOM. After this method any operation with XML is not
available.
saveAs
saveAs(string path)
path
The valid path of the file to save the XML data to.
The saveAs method saves content to an XML file. If successful, saveAs returns
CPXMLErr:NoError . Otherwise, it returns CPXMLErr:XMLWriteFail.
Return Value: BYTE
29
toXML
toXML(StructWrapper sw, <string nodeName>,byte positionFlag=APPEND)
sw
nodeName
The name of the created node (optional parameter). The parameter is used only
if positionFlag =XMLPos:APPEND_CHILD.
PositionFlag
XMLPos:APPEND_CHILD
The toXML method loads data from a Clarion structure. It returns CPXMLErr:NoError if
successful. Otherwise, toXML returns CPXMLErr:CreateDOMFail.
If some data has been previously loaded, then the method just appends the new data to the
existing data. You can select XML node (in the setNode method) to point at the position where
the data should be loaded to.
Return Value: BYTE
fromXML
fromXML
sw
procedure(StructWrapper sw)
The fromXML method puts the data from the DOM Document object to a Clarions object. It
returns CPXMLErr:NoError if successful. Otherwise, the method returns CPXMLErr:ImportFail.
You can select the necessary XML node for this operation with the setNode method.
Return Value: BYTE
30
setNode
setNode(*Node nd)
nd
getNode
getNode( ),*Node
The getNode method returns the pointer to the current XML DOM Node object.
getNavigator
getNavigator( ),*XMLNavigator
The getNavigator method gets the instance of the XMLNavigator class. It returns a pointer to the
XMLNavigator object.
getDocument
getDocument( ),*Document
The getDocument method returns the reference to XML DOM Document object.
31
attachDOM
attachDOM(*Document doc)
doc
After calling this method all export/import operation will work with the attached document. On
destruction/closing of the XMLExchange object the release method for the Document is
automatically called.
detachDOM
detachDOM( ), *Document
The detachDOM method detaches the wrappers DOM Document. It returns the pointer to the
inner XML DOM Document object.
After the call of the method, no export/import operations are available. Its the responsibility of the
user to release the detached Document.
setStyle
setStyle(XMLStyle style)
style
specify the style of generated XML. It can be XMLStyle:ADO_26 (for attributebased style) or XMLStyle:ADO_Net (for tag-based)
The setStyle method sets the style that is used for import/export operations.
32
getTimeCreated
getTimeCreated( )
The getTimeCreated method returns the string with date and time information assigned to the
current node in the following format:
Yyyy/mm/dd hh:mm:ss
Return value: STRING
getVersion
getVersion( )
The getVersion method returns the string with the version information assigned to the current
node.
Return value: STRING
getUserInfo
getUserInfo( )
The getUserInfo method returns the string with user defined information assigned to the current
node.
Return value: STRING
setUserInfo
setUserInfo(string ui)
ui
The setUserInfo method assigns the user-defined string to the current XML node
setSpecAttrOn
setSpecAttrOn(byte flag=true)
flag
The setSpecAttrOn method sets the mode (On/Off) for special attributes (Version, style,
timestamp etc.).
By default all special attributes are included and added to the node after each toXML method
call.
setRootTagName
setRootTagName(string tagName)
tagName
The name of the root tag. By default the name of the root tag is dataroot.
33
34
setRowTagName
setRowTagName(string tagName)
tagName
The name of the row tag. By default the name of the row tag is row for style
XMLStyle:ADO_26 and table for style XMLStyle:ADO_Net.
The setRowtagName method sets the name of the tag that is used for a row of data
setMaxRowCount
setMaxRowCount(unsigned maxCou), byte
maxCou
The setMaxRowCount method sets the maximum number of rows to be retrieved. If successful,
the method returns CPXMLErr:NoError .Otherwise, it will return CPXMLErr:IllegalParameter.
35
XMLNavigator Class
The XMLNavigator class provides basic functionality to navigate through an XML Document
object contained in the XMLExchange object. You can retrieve the reference to the instance of
the class with getNavigator method of an XMLExchange object.
The getXMLExchangeNode method gets the current node of the XMLExchange object and sets
the current node of XMLNavigator to the retrieved value
setXMLExchangeNode
setXMLExchangeNode( )
The setXMLExchangeNode method sets the current node of the XMLExchange object to the
current node of the XMLNavigator.
goToRoot
goToRoot( )
The goToRoot method moves the inner current node pointer to the root node of the DOM
Document. It returns a TRUE if successful, and FALSE otherwise.
Return value: BYTE
36
goToParent
goToParent( )
The goToParent method moves the current node pointer to the parent node relative to the
current node value. It returns a TRUE if successful, and FALSE otherwise.
Return value: BYTE
goToFirstChild
goToFirstChild( )
The goToFirstChild method moves the current node pointer to the first child node relatively to
current node value. It returns a TRUE if successful, and FALSE otherwise.
Return value: BYTE
goToNextSibling
goToNextSibling( )
The goToNextSibling method moves the current node pointer to the next sibling node relatively
to current node value. It returns a TRUE if successful, and FALSE otherwise.
Return value: BYTE
getNodeName
getNodeName( )
37
getNodeAttributes
getNodeAttributes(AttrQueue aq
aq
The label of a QUEUE (AttrQueue). The AttrQueue contains records with following fields:
AttrName contains name of an attribute
AttrValue contains value of the attribute
The getNodeAttributes method fills the QUEUE structure with attributes information in the form
of pairs:
<attribute_name,attribute_value>
getNodeAttributes returns a TRUE if successful, and FALSE otherwise.
Return value: BYTE
38
Error codes
The following return codes can be returned by the XML methods:
Codes
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Description
No error occurred
Error reading an XML file
Error writing to an XML file
Error: an attempt to use the same field name twice (duplicate name)
name cannot be used as XML tag/attribute identifier
Error creating XML DOM Document object
End Of File
Invalid Argument
Illegal Function Call
Not supported
Internal error
Field not found
General Error
Illegal parameter
Import Failure
39
Exporting data from FILE, VIEW or QUEUE structures to an XML DOM Document object
Importing data from a XML DOM Document object to FILE or QUEUE structures
Importing data from XML file or string to an XML DOM Document object
This set of functions provides the possibility to export data from FILE, VIEW or QUEUE structures
to an XML file (or string) and import data from an XML file (or string) to FILE or QUEUE
structures.
The implementation of these functions is based on the C++ library from CenterPoint that provides
basic functionality to work with XML data. The classes from the library are available from Clarion
through a set of wrapper functions.
User model
The current set of functions includes the following:
DOMToFile, DOMToQueue provide import data from XML DOM Document object to
the corresponding XML structures
40
Comments:
All functions xxxToDOM return a pointer to a Document object. When the developer is done with
the Document object its necessary to free memory by calling the Release method. Typical code
looks like this:
Doc
&Document, auto
Code
Doc=GroupToDOM(GR)
IF(NOT Doc& = NULL)
Doc.Release
END
ToXMLFile
Exports data of FILE, VIEW, QUEUE or GROUP structure to the given XML file (the
implementation includes several version of overloaded function with a different parameter for
each type of Clarions structure (FILE, VIEW, QUEUE or GROUP)
FromXMLFile
Imports data of FILE, QUEUE or GROUP structure from the given XML file (this function is also
overloaded).
GetLastError
GetLastError is used to provide more detailed information about XML based errors. The function
returns the last error code produced by the last XML function call.
See the Error Table for a complete list of possible errors.
Conceptual Example
Lets consider the following XML files:
Customer.XML (Contains information about customers)
<?xml version="1.0"?>
<data>
<row lastname="Wright" firstname="Carl" phone="222-1697"/>
<row lastname="Curry" firstname="Charmaine" phone="333-9716"/>
</data>
41
42
Example code:
PROGRAM
INCLUDE('CPXML.INC'),ONCE
MAP
END
CC
BYTE
Customer QUEUE
LastName STRING(30)
Phone
STRING(30)
END
NameMap QUEUE(MapQueue)
END
code
!Import data from file Customer.xml to Customer QUEUE.
!Destination QUEUE contains only LastName, Phone fields so data
!fields is imported
cc = FromXMLFile(Customer,Customer.xml)
if (CC)
!Export data from Customer QUEUE to a file with name mapping
! Loading name mapping information from NAMEMAP.XML
CC=FromXMLFile(NameMap,NameMap.xml)
IF(CC)
CC = ToXMLFile(Customer,CustomerData.xml,NameMap)
IF(NOT CC)
STOP(Exporting error)
END
ELSE
STOP(NameMap.xml importing error)
END
ELSE
STOP(Customer.xml importing error)
END
tel="333-9716"/>
The generated code will call the File Open dialog to specify the name of an XML file for
export/import operation, an optional dialog to specify XML file with name mapping
information and the call to the corresponding function (ToXMLFile for export or
FromXMLFile for import).
43
44
45
46
Doc
Format
path
que
fl
gr
vw
label
style
The style of the generated XML file. Can be:DOMStyle:ADO_26 (attributebased style) or DOMStyle:ADO_Net (tag-based style)
map
removePrefix
maxRowCount
Description
No errors occur
Error reading an XML file
Error writing to a XML file
Error: an attempt to use the same field name twice (duplicate name)
A name can be used as XML tag/attribute identifier
Error creating XML DOM Document object
EOF (End of File)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Invalid Argument
Illegal Function Call
Not Supported
Internal Error
Field Not Found
Common Error
Illegal Parameter
Import Fail
Not Successful
Illegal Format
Illegal Type
Illegal Size
No Such Field
EOS (End of Sequence)
Schema Not Supported
Inconsistent Schema
Check Fail
Add Record Failed
Invalid Node Name
No Current Node
Cdata Not Supported
Base64 Not Supported
47