roXMLElement
Â
This object is used to contain an XML tree. The JavaScript equivalent is DOMParser()
.
The roXMLElement object is created with no parameters:Â
CreateObject("roXMLElement")
Â
The following examples illustrate how XML elements are parsed in BrightScript:
<tag1>This is example text</tag1>
Name = tag1
Attributes = Invalid
Body = roString containing "This is example text"
Â
<tag2 caveman="barney"/>
Name = tag2
Attributes = roAssociativeArray with one entry,Â
{caveman, barney}
Body = Invalid
If the tag contains other tags, the body will be of type roXMLList.
To generate XML content, create an roXMLElement and call the SetBody()
 and SetName()
 methods to build it–then call the GenXML()
 method to generate it.
Example
ifXMLElement
GetBody() As Object
Â
GetAttributes() As Object
Â
GetName() As String
Â
GetText() As String
Â
GetChildElements() As Object
Â
GetNamedElements(a As String) As Object
Â
GetNamedElementsCi(a As String) As Object
Â
SetBody(a As Object)
Generates an roXMLList for the body if needed. The method then adds the passed item (which should be an roXMLElement tag).
AddBodyElement() As Object
Â
AddElement(a As String) As Object
Â
AddElementWithBody(a As String, b As Object) As Object
Â
AddAttribute(a As String, b As String)
Â
SetName(a As String)
Â
Parse(a As String) As Boolean
Parses the XML content passed to it. In the event of failure, this method returns False. However, it also populates roXMLElement with whatever text could be successfully parsed. To avoid passing along erroneous strings, it is always best to have the script check the return value of Parse()
 before using them.
GenXML(a As Boolean) As String
Generates XML content. This method takes a single Boolean parameter, indicating whether or not the XML should have an <?xml …>
 tag at the top.
Clear() As Void
Â
GenXMLHdr(a As String) As String
Â
IsName(a As String) As Boolean
Â
HasAttribute(a As String) As Boolean
Â
ParseFile(a As String) As Boolean
Example
This subroutine example prints out the contents of an roXMLElement tree:
Â