Home
Main Introduction Features Constants Statements Database Objects Parser Serial-Communication Samples Misc
Parser>XML
Caravan Business Server>Help>Parser>XML
Syntax object objname="filename"; // creates an object from the file
Text Caravan support for XML is designed to make XML data accessible in Caravan language, without a steep learning curve for the programmer. Caravan can parse XML documents from static files or web sources and create XML objects which are similar to Caravan objects.
Objects are tree structured and special keywords areused to traverse the tree since there are nodes and leaves. Nodes can have attribute/s and other nodes and leaves but can have no value. Leaves can have a value and attribute/s.
Sample object xmlvar="f:\xmldata\serverconfig.xml"; // creates an object from the file
XML file to illustrate the object syntax and usage.
<xml>
<company>
<name>Niti Telecom</name>
</business>Software
<employee>
<name>Nitin Kedia</name>
<designation>Owner<designation>
<email>nitink@vsnl.net.in</email>
<phone>6443825</phone>
</employee>
<employee>
<name>Manoj K G</name>
<designation>Engineer<designation>
<email>manoj_kgm@yahoo.com</email>
<phone>4015264</phone>
</employee>
<phone>6556412</phone>
<phone>6556403</phone>
<phone>6552193</phone>
</company>
<company>
<name>Link Era</name>
</business>E-commerce
<employee>
<name>Nitin Kedia</name>
<designation>Owner<designation>
<email>nitink@vsnl.net.in</email>
<phone>6443825</phone>
</employee>
<employee>
<name>Kiran Hegde</name>
<designation>Partner<designation>
<email>kiranhe@yahoo.com</email>
<phone>4548-899666</phone>
</employee>
<phone>6556412</phone>
<phone>6556403</phone>
<phone>6552193</phone>
</company>
</xml>

In this example, company is a node and has employee as nodes. The phone number, business and name of the company are leaves of the company.
An object company (cmp) is created with the focus at the root.
object cmp="http://www.nititelecom.com/companyinfo.xml"
cmp(.name) returns the name of the programming language -- "xml".
cmp(company(@0)) returns 2 -- the number of elements of type company. In the example details of two companies have been entered.
cmp(.node)="company" defines the node as company.
cmp(name) returns "Niti Telecom", the name of the first company.
In the above example there are two elements of type company. The keywords .next and .previous can be used to access the next company and the previous company.
cmp(.node)=".next" focusses on the next node-in this example, the next company.
cmp(name) returns "Link Era", the name of the second company.
In this example there are only two companies defined. Hence there is no next node following this node.
cmp(.node)=".next" does not focus on a next company but sets the .error property.
cmp(.error) gives the message "node unchanged", since a third company has not been defined.
Note that .name is a keyword for accessing the name of the node.
cmp(employee(@0)) returns 2 -- number of employees in "Link Era", the second company defined.
The object properties are state dependant. You can specify the node as .previous or .next or root to access object properties of the previous node, next node or the root.
cmp(.node)=".previous" goes back to the previous node.
cmp(name) returns "Niti Telecom", the name of the first company.
cmp(.node)="root" goes back to the root.
To check whether the parsing was successful, the .errorproperty can be used. In case of parse error, object is empty. To check whether the node change was effective, the .error property can be used.
cmp(phone) gives all the phone numbers.
cmp(phone(@0)) gives 3 - the number of telephone numbers for the first node company.
cmp(phone(@1)) gives 6556412 - the first phone number.
The XML syntax is used with all Caravan objects.
Properties .node
.root
.next
.previous
.name
.error
.attribute
Back