Forum Discussion

nanuto's avatar
nanuto
Visitor
11 years ago

XML function Parse

Hi, this my function

Function login()

searchRequest=CreateObject("roUrlTransfer")
searchRequest.SetURL(host() + "?xid=start")
result = searchRequest.GetToString()
return result


i call it as print login() the debuger looks like...from the request to my host,


<?xml version='1.0' encoding='iso-8859-1'?>
<User>
<Rcode>text</Rcode>
<Uname>username</Uname>
<Status>Hi im active.</Status>
</User>


but wow can i access to the elements. i try this way,
myxml = login()
list = CreateObject("roXMLElement")
list.Parse(myxml)
print list.user.Uname.GetText()
print list.Uname.GetText()


Thank for the help.

2 Replies

  • <User> is the root element, so filter w/o it:

    BrightScript Debugger> xml = createObject("roXmlElement")
    BrightScript Debugger> ? xml.parse("<User><Rcode>text</Rcode><Uname>username</Uname><Status>Hi im active.</Status></User>")
    true
    BrightScript Debugger> ? xml.Uname.getText()
    username
  • Thanks thats worked!,
    another solution that i share

    root = xml.getChildElements()
    Status_e = xml.getNamedElements("Status")
    Status = Status_e[0].gettext()


    Thank you :).