Player APIs (BrightScript & Ja...
...
Object Reference
BrightScript Core Objects

roXMLElement

16min
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 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 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 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