Because BrightScript has support for parsing XML built in to the language, it is often more convenient to use those features rather than ifXMLElement methods. See BrightScript XML Support for more details.
Implemented By
Supported Methods
- Parse(xml as String) as Boolean
- GetBody() as Object
- GetAttributes() as Object
- GetName() as String
- GetText() as String
- GetChildElements() as Object
- GetChildNodes() as Object
- GetNamedElements(name as String) as Object
- GetNamedElementsCi(name as String) as Object
- IsName(name as String) as Boolean
- HasAttribute(attr as String) as Boolean
- SetBody(body as Object) as Void
- AddBodyElement() as Object
- AddElement(name as String) as Object
- AddElementWithBody(name as String, body as Object) as Object
- AddText(text as String) as Void
- AddAttribute(attr as String, value as String) as Void
- SetName(name as String) as Void
- GenXML(gen_header as Boolean) as String
- GenXMLHdr(hdr as String)
- Clear() as Void
Description of Methods
Parse(xml as String) as Boolean
Parse a string of XML. Returns true if successful. In that case, other methods below can then be used to extract information about the parsed element.
GetBody() as Object
Returns the body of the element. If the element contains child elements, GetBody() returns an roXMLList representing those elements, like GetChildElements(). If there are no children but the element contains text, GetBody() returns an roString like GetText(). If the element is empty, GetBody() returns invalid.
GetAttributes() as Object
Returns an Associative Array representing the XML attributes of the element.
GetName() as String
Returns the name of the element.
GetText() as String
Returns any text contained in the element. This returns immediate body text only, i.e. does not include text from child elements.
GetChildElements() as Object
If there are child elements contained in this one, returns an roXMLList representing those elements. If there are no child elements, returns invalid. Note that this function won't handle cases of mixed XML content, i.e., content with both child elements and text such as:
<element><child>Child Text</child>More Text</element>
In this case GetChildElements() called with the top level <element> as an argument would return an roXMLList containing only one item corresponding to the <child> element. The body text "More Text" would be lost. To handle mixed content cases, use GetChildNodes().
GetChildNodes() as Object
If there are child elements contained in this one, returns an roList representing those elements. If there are no child elements, returns invalid. The difference between this function and GetChildElements() is that GetChildNodes() handles the case of mixed XML content, i.e., content with both child elements and text such as:
<element><child>Child Text</child>More Text</element>
In this case GetChildNodes() called with the top level <element> as an argument would return an roList with two elements. The first element would be an roXMLElement containing the information about <child>. The second would be an roString containing "More Text".
GetNamedElements(name as String) as Object
Returns an roXMLList representing all child elements of this element whose name is specified. If only one element matches the name, an roXMLList containing one element is returned. If no elements match, an empty roXMLList is returned.
GetNamedElementsCi(name as String) as Object
Same as GetNamedElements except the name matching is case-insensitive.
IsName(name as String) as Boolean
Returns true if the element has the specified name.
HasAttribute(attr as String) as Boolean
Returns true if the element has the specified attribute.
SetBody(body as Object) as Void
Sets the element text from the specified string.
AddBodyElement() as Object
Adds an new unnamed / empty child element and returns it. This should generally be followed by a call to child.SetName(). Alternatively AddElement() or AddElementWidthBody() can be used to combine this step with additional construction into one call.
AddElement(name as String) as Object
Adds a new child element with the specified name and returns the new element.
AddElementWithBody(name as String, body as Object) as Object
Adds a new child element with the specified name and text from the specified body string, and returns the new element.
AddText(text as String) as Void
Adds text to the element.
AddAttribute(attr as String, value as String) as Void
Adds an attribute value to the element. If an attribute of the same name already exists it is replaced. Note that XML attribute order is not significant, i.e. not preserved.
SetName(name as String) as Void
Sets the name of the element.
GenXML(gen_header as Boolean) as String
Serializes the element to XML document text. If gen_header is true then the output begins with a standard XML declaration specifying UTF-8 encoding.
GenXMLHdr(hdr as String)
Serializes the element to XML document text. The specified header is used to begin the output, for example as a custom XML declaration.
Clear() as Void
Removes all attributes and children from the element, as well as setting the name to empty.