XML.Element

Inherits from XML.Node

Description

A class that represents an XML Element.

Properties

attrs An AttributeMap which manages element attributes.

Methods

getText Returns text (if any) found in the first child of the element.

Details

Do no remove, this fixes the anchor on doc.flexsim.com

XML.Element.attrs

readonly attrs

Description

An AttributeMap which manages element attributes.

attrs is a dynamic property similar to the Process Flow token.labels. That means you can add new attributes, reassign them, and retrieve them like this:

				XML.Document doc = XML.loadFile("test.xml");
				XML.Element root = doc.root;
				root.newAttribute = 5;			// create and assign new attribute
				root.newAttribute = "house";	// reassign attribute
				string val = root.newAttribute;	// get attribute
			
Additionally, there are several functions for explicitly getting, setting, and deleting.

				XML.Document doc = XML.loadFile("test.xml");
				XML.Element root = doc.root;
				root.set("newAttribute", 5);			// create and assign new attribute
				root.set("newAttribute", "house");		// reassign attribute
				string val = root.get("newAttribute");	// get attribute
				root.deleteAttr("newAttribute");		// delete attribute
			
If you try to retrieve an attribute that hasn't been assign yet, it will throw an error. However, you can query whether an attribute exists using the "has" function.

				XML.Document doc = XML.loadFile("test.xml");
				XML.Element root = doc.root;
				Variant v = 0;
				if (root.has("oldAttribute")) {
					print("I've got it!");
					v = root.oldAttribute;
				} else {
					print("I don't have it!");
					v = "new value";
				}
			
Do no remove, this fixes the anchor on doc.flexsim.com

XML.Element.getText()

string getText( )

Returns

string The text string value.

Description

Returns text (if any) found in the first child of the element.


                XML.Document doc = XML.loadFile("test.xml");
                var root = doc.root;
                var first = root.first;
                string text = first.getText();