beautypg.com

BrightSign BrightScript 2 Reference Guide User Manual

Page 49

background image

49



Would parse such that:
Name= emptytag
Attributes = roAssociatveArray, with one entry {caveman, barney)
Body = invalid

If the tag contains other tags, body will by of type “roXMLList”.

To generate XML, create an roXMLElement, then use the “Set” functions to
build it. Then call GenXML().

GenXML() takes one parameter (boolean) that indicates whether the generated xml
should have the tag at the top.

AddBody() will create an roXMLList for body, if needed, then add the passed item
(which should be an roXMLElement tag).


Example subroutine to print out the contents of an roXMLElement tree:

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 ", ";
next
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)
next
end if
print
end sub

Example of generating XML:

root.SetName("myroot")
root.AddAttribute("key1","value1")