Scriptol/Xml or class

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Xml or class[edit | edit source]

Common class[edit | edit source]

Scriptol is object-oriented and has classes and inheritance. Defining a class is easy. Example of a very simple class.

class car
  int speed
  void getSpeed()
     ... some statements ...
  return speed 
/class 


Xml[edit | edit source]

But Scriptol has also xml. Defining a xml document is simple also.

xml Car
  speed value = "10" /
  wheels number = "4"
  passengers number = "5"
     Clara, Charly, Corinna, Cyril, Cecilia
  /passengers  
/xml 


Using Xml[edit | edit source]

Classes are used directly or by creating an instance, and making reference to attributes or calls to methods.

Using Xml is not different. You can define how many instances of xml documents you want, and modify the content of each of them. The content of elements or attributes may be assigned, and elements and attributes may be added of removed.

Car myCar ` myCar is an instance of the Car Xml document.
print myCar.speed ` displaying the value of the "speed" attribute.
print myCar.passengers ` displaying the content of the "passengers" tag.

Importing xml document[edit | edit source]

Xml is mainly useful for performing processes on documents produced by various tools, word processors, spreadsheets, etc....

To load such documents, Scriptol integrates a sax parser. You have just to declare a xml document, load le xml file, and you can use the document as a class declared in the source.

xml Car ` declaring an empty xml document.
/xml
Car myCar` defining an instance (not required).
myCar.load("document.xml")  ` loading an external xml document
Car.load("document.xml")  ` you can use directly the xml class itself 


Iterator[edit | edit source]

Iterator on xml document is as iterator on array, plus the down() and up() methods. Iterator allows to parse an entire xml document or just sub-elements of of an element.


demo.begin() 
while demo.isFound() 
print demo.getData() 
let demo.inc()