XML variables:

This language has special xml variable which help with operations on xml.


Declaration

Unfortunetly xml variables need to be declared, we cannot use them with auto declaration, so everytime we want to use them we need to declare. Below is example.

xml Root;

Tag name

by default tag name will be the same as variable name, so our example declaration will create xml document with tag "Root"

xml Root; 
console(string(Root));
We should see xml document like this:
<Root></Root>

If we don't want to have the same tag name as variable name we can set or get tag name by using propertie "name"

Geting tag name:
xml Root; 
tagname = Root:name();
console(tagname);
We should see xml document like this:
Root
Seting tag name:
xml Root; 
Root:name("Document");
console(string(Root));
We should see xml document like this:
<Document></Document>

Basic operations (static)

We can easy do basic et/get operation on all tag values in xml document. Below few examples with decriptions.

Setting attribute
Source:
xml Root; 
Root:lang = "English";
console(string(Root));
Output:
<Root lang="English"></Root>
Setting child tag
Source:
xml Root; 
Root.Store = "List of books";
console(string(Root));
Output:
<Root>
  <Store>List of books</Store>
</Root>
Setting child tag attribute
Source:
xml Root; 
Root.Store.Book:name = "Moby Dick";
console(string(Root));
Output:
<Root>
  <Store>
    <Book name="Moby Dick"></Book>
  </Store>
</Root>
Setting tags and attributes
Source:
xml Root; 
Root.Store.Book:name = "Moby Dick";
Root.Store.Book:author = "Herman Melville";
Root.Store.Book.Description = "Not availabe yet";
console(string(Root));
Output:
<Root>
  <Store>
    <Book name="Moby Dick" author="Herman Melville">
      <Description>Not availabe yet</Description>
    </Book>
  </Store>
</Root>
Getting tags and attributes
Source:
xml Root = xml("<Root>
  <Store>
    <Book name="Moby Dick" author="Herman Melville">
      <Description>Not availabe yet</Description>
    </Book>
  </Store>
</Root>"); 

console(Root.Store.Book:name);
console(Root.Store.Book.Description);
Output:
Moby Dick
Not availabe yet
Setting Multiple tags with same name
Source:
xml Root;

Root.Store.Book[0]:name = "Moby Dick";
Root.Store.Book[0]:author = "Herman Melville";
Root.Store.Book[0].Description = "Not availabe yet";

Root.Store.Book[1]:name = "The Odyssey";
Root.Store.Book[1]:author = "Homer";
Root.Store.Book[1].Description = "Not availabe yet";

Root.Store.Book[2]:name = "Catch-22";
Root.Store.Book[2]:author = "Joseph Heller";
Root.Store.Book[2].Description = "Not availabe yet";

console(string(Root))
Output:
<Root>
  <Store>
    <Book name="Moby Dick" author="Herman Melville">
      <Description>Not availabe yet</Description>
    </Book>
    <Book name="The Odyssey" author="Homer">
      <Description>Not availabe yet</Description>
    </Book>
    <Book name="Catch-22" author="Joseph Heller">
      <Description>Not availabe yet</Description>
    </Book>
  </Store>
</Root>
Getting Multiple tags with same name
Source:
xml Root = xml("<Root>
  <Store>
    <Book name="Moby Dick" author="Herman Melville">
      <Description>Not availabe yet</Description>
    </Book>
    <Book name="The Odyssey" author="Homer">
      <Description>Not availabe yet</Description>
    </Book>
    <Book name="Catch-22" author="Joseph Heller">
      <Description>Not availabe yet</Description>
    </Book>
  </Store>
</Root>"); 

console("Books: " + string(Root.Store.Book:count1()))
console(Root.Store.Book[0]:name);
console(Root.Store.Book[1]:name);
console(Root.Store.Book[2]:name);
Output:
Books: 3
Moby Dick
The Odyssey
Catch-22

XML Properties:

Xml variable has properties, we already used "name()" and "count1()", below is list of all properties with description

void xml:empty() - Empty all xml structure...(Free all child xml structure, only current stays)
void xml:free() - Free all xml structure (including current)
void xml:load(string) - Load XML from file
void xml:save(string) - Save XML into file
string xml:string() - Return XML as string.
void xml:name(string) - Set name of this tag
string xml:name() - Get name of this tag
string xml:value() - Get value of xml tag;
void xml:value(string) - Set value of xml tag;
xml xml:find(int,string) - Find element/tag by name
xml xml:create(int,string) - Find or Create element/tag by name
xml xml:find3(int) - Find/Get element/tag by number
int xml:childs() - Get number of child
int xml:count1() - Get number of tags named the same as current
int xml:count2(string) - Get number of tags named by string (this is "childs()" with name)
int xml:attrcnt() - Count attributes
string xml:attrget1(string) - Get attribute value
string xml:attrget2(int) - Get attribute value
string xml:attrname(int) - Get attribute name
void xml:attrset1(string,string) - Set attribute value
void xml:attrset2(int,string) - Set attribute value
void xml:add(xml1) - Add/Append xml1 to xml
void xml:del1(xml1) - Remove child (xml1) from parent (xml)
void xml:del2() - Remove child
void xml:del3(int) - Remove child by number
bool xml:next() - Set xml to next tag and return false if end
xml xml:next1() - Return next tag
bool xml:isok() - If xml if ok, or it's null