Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added JS equivalent

...

Insert excerpt
BrightScript Version Navigation Menu
BrightScript Version Navigation Menu
nopaneltrue
This object is used to contain an XML tree. The JavaScript equivalent is DOMParser().

The roXMLElement object is created with no parameters: 

...

  • Name = tag1
  • Attributes = Invalid
  • Body = roString containing "This is example text"

...


Code Block
<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.

...

Code Block
titleExample
root.SetName("myroot")
root.AddAttribute("key1","value1")
root.AddAttribute("key2","value2")
ne=root.AddBodyElement()
ne.SetName("sub")
ne.SetBody("this is the sub1 text")
ne=root.AddBodyElement()
ne.SetName("subelement2")
ne.SetBody("more sub text")
ne.AddAttribute("k","v")
ne=root.AddElement("subelement3")
ne.SetBody("more sub text 3")
root.AddElementWithBody("sub","another sub (#4)")
PrintXML(root, 0)
print root.GenXML(false)


 

ifXMLElement

GetBody() As Object
 

...

ParseFile(a As String) As Boolean

...

 


...


The following is an example subroutine to print out the contents of an roXMLElement tree:

...


Code Block
PrintXML(root, 0)

Sub PrintXML(element As Object, depth As Integer)
    print tab(depth*3);"Name: ";element.GetName()
    if not element.GetAttributes().IsEmpty() then
        print tab(depth*3);"Attributes: ";
        for each a in element.GetAttributes()
            print a;"=";left(element.GetAttributes()[a], 20);
            if element.GetAttributes().IsNext() then print ", ";
        end for
        print
    end if
    if element.GetText()<>invalid then
        print tab(depth*3);"Contains Text: ";left(element.GetText(), 40)
    end if
    if element.GetChildElements()<>invalid
        print tab(depth*3);"Contains roXMLList:"
        for each e in element.GetChildElements()
            PrintXML(e, depth+1)
        end for
    end if
    print
end sub