Bundle XML parsing and building library. XmlParser reads XML into an XmlElement tree with attribute and child-node navigation; XmlBuilder constructs XML documents. Compile with -lib xml.
XmlBuilder
Used to programmatically build XML documents
Example
builder := XmlBuilder->New("root");
builder->AddTextElement("name", "John");
builder->AddTextElement("age", "30");
builder->ToString()->PrintLine();Operations
GetEncoding #
Gets the XML encoding
method : public : GetEncoding() ~ StringReturn
| Type | Description |
|---|---|
| String | XML encoding |
Example
builder := XmlBuilder->New("root", "1.0", "UTF-8");
builder->GetEncoding()->PrintLine();GetRoot #
Returns the root node of the XML document
method : public : GetRoot() ~ XmlElementReturn
| Type | Description |
|---|---|
| XmlElement | root node |
Example
builder := XmlBuilder->New("items");
root := builder->GetRoot();
root->SetContent("hello");
builder->ToString()->PrintLine();GetVersion #
Gets the XML version
method : public : GetVersion() ~ StringReturn
| Type | Description |
|---|---|
| String | XML version |
Example
builder := XmlBuilder->New("root", "1.0");
builder->GetVersion()->PrintLine();New # constructor
Default constructor
New(name:String)Parameters
| Name | Type | Description |
|---|---|---|
| name | String | root element name |
Example
builder := XmlBuilder->New("catalog");
builder->GetRoot()->AddChild(XmlElement->New(XmlElement->Type->ELEMENT, "book"));
builder->ToString()->PrintLine();New # constructor
Default constructor
New(name:String, version:String)Parameters
| Name | Type | Description |
|---|---|---|
| name | String | root element name |
| version | String | XML version tag |
Example
builder := XmlBuilder->New("root", "1.0");
builder->ToString()->PrintLine();New # constructor
Default constructor
New(name:String, version:String, encoding:String)Parameters
| Name | Type | Description |
|---|---|---|
| name | String | root element name |
| version | String | XML version tag |
| encoding | String | XML encoding type |
Example
builder := XmlBuilder->New("root", "1.0", "UTF-8");
builder->ToString()->PrintLine();SetEncoding #
Sets the XML encoding
method : public : SetEncoding(encoding:String) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| encoding | String | encoding version |
Return
| Type | Description |
|---|---|
| Nil | XML encoding |
Example
builder := XmlBuilder->New("root", "1.0");
builder->SetEncoding("UTF-8");
builder->GetEncoding()->PrintLine();SetVersion #
Sets the XML version
method : public : SetVersion(version:String) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| version | String | version |
Return
| Type | Description |
|---|---|
| Nil | XML version |
Example
builder := XmlBuilder->New("root");
builder->SetVersion("1.1");
builder->GetVersion()->PrintLine();ToString #
Produces an XML string representation of the document
method : public : ToString() ~ StringReturn
| Type | Description |
|---|---|
| String | string representation of the document |
Example
builder := XmlBuilder->New("root", "1.0", "UTF-8");
child := XmlElement->New(XmlElement->Type->ELEMENT, "name");
child->SetContent("Alice");
builder->GetRoot()->AddChild(child);
builder->ToString()->PrintLine();