Histórico da Página
...
Bloco de código | ||||||
---|---|---|---|---|---|---|
| ||||||
#------------------------------# FUNCTION LXMLObjectTest() #------------------------------# DEFINE l_xml TEXT DEFINE l_xml_obj_ref VARCHAR(10) DEFINE l_break CHAR(002) DEFINE l_value CHAR(100) DEFINE l_status SMALLINT IF LOG_isSrvUnix() = "U" THEN LET l_break = ASCII(10) ELSE LET l_break = ASCII(13) LET l_break = l_break CLIPPED, ASCII(10) END IF LET l_xml = '<?xml version="1.0"?>' || l_break LET l_xml = l_xml CLIPPED || '<bookStore name="Saraiva" country="BR">' || l_break LET l_xml = l_xml CLIPPED || ' <foundation>' || l_break LET l_xml = l_xml CLIPPED || ' <founder>Seu Saraiva</founder>' || l_break LET l_xml = l_xml CLIPPED || ' <year>1914</year>' || l_break LET l_xml = l_xml CLIPPED || ' </foundation>' || l_break LET l_xml = l_xml CLIPPED || ' <books>' || l_break LET l_xml = l_xml CLIPPED || ' <book isNew="true">' || l_break LET l_xml = l_xml CLIPPED || ' <title>A Game of Thrones</title>' || l_break LET l_xml = l_xml CLIPPED || ' <author>George R. R. Martin</author>' || l_break LET l_xml = l_xml CLIPPED || ' <price>9.99</price>' || l_break LET l_xml = l_xml CLIPPED || ' <origin>US</origin>' || l_break LET l_xml = l_xml CLIPPED || ' </book>' || l_break LET l_xml = l_xml CLIPPED || ' <book isNew="false">' || l_break LET l_xml = l_xml CLIPPED || ' <title>A Clash of Kings</title>' || l_break LET l_xml = l_xml CLIPPED || ' <author>George R. R. Martin</author>' || l_break LET l_xml = l_xml CLIPPED || ' <price>9.99</price>' || l_break LET l_xml = l_xml CLIPPED || ' <origin>US</origin>' || l_break LET l_xml = l_xml CLIPPED || ' </book>' || l_break LET l_xml = l_xml CLIPPED || ' </books>' || l_break LET l_xml = l_xml CLIPPED || '</bookStore>' || l_break LET l_xml_obj_ref = _ADVPL_create_component(NULL,"LXMLOBJECT") # GET ACTIVATE: valida e inicia a interpretação do XML. LET l_status = _ADVPL_get_property(l_xml_obj_ref,"ACTIVATE",l_xml) IF l_status THEN CALL CONOUT("LXMLOBJECT GET ACTIVATE1 OK") ELSE CALL CONOUT("LXMLOBJECT GET ACTIVATE1 NOK") CALL CONOUT("ERROR = "+_ADVPL_get_property(l_xml_obj_ref,"ERROR_MESSAGE")) RETURN FALSE END IF # GET ATTR_VALUE: Recupera o valor de determinado atributo de um nó informado. LET l_value = _ADVPL_get_property(l_xml_obj_ref,"ATTR_VALUE","/bookStore/books/book[1]","isNew") IF l_value = "true" THEN CALL CONOUT("LXMLOBJECT ATTR_VALUE (/bookStore/books/book[1] isNew) OK " || l_value CLIPPED) ELSE CALL CONOUT("LXMLOBJECT ATTR_VALUE (/bookStore/books/book[1] isNew) NOK " || l_value CLIPPED) END IF # GET ATTR_VALUE: Recupera o valor de determinado atributo de um nó informado. LET l_value = _ADVPL_get_property(l_xml_obj_ref,"ATTR_VALUE","/bookStore/books/book[2]","isNew") IF l_value = "false" THEN CALL CONOUT("LXMLOBJECT ATTR_VALUE (/bookStore/books/book[2] isNew) OK " || l_value CLIPPED) ELSE CALL CONOUT("LXMLOBJECT ATTR_VALUE (/bookStore/books/book[2] isNew) NOK " || l_value CLIPPED) END IF # GET NODE_VALUE: Recupera o valor de determinado nó filho de um nó pai informado. LET l_value = _ADVPL_get_property(l_xml_obj_ref,"NODE_VALUE","/bookStore/books/book[1]/title") IF l_value = "A Game of Thrones" THEN CALL CONOUT("LXMLOBJECT GET NODE_VALUE /bookStore/books/book[1]/title OK " || l_value CLIPPED) ELSE CALL CONOUT("LXMLOBJECT GET NODE_VALUE /bookStore/books/book[1]/title NOK " || l_value CLIPPED) END IF # GET NODE_VALUE: Recupera o valor de determinado nó filho de um nó pai informado. LET l_value = _ADVPL_get_property(l_xml_obj_ref,"NODE_VALUE","/bookStore/books/book[2]/title") IF l_value = "A Clash of Kings" THEN CALL CONOUT("LXMLOBJECT GET NODE_VALUE /bookStore/books/book[2]/title OK" || l_value CLIPPED) ELSE CALL CONOUT("LXMLOBJECT GET NODE_VALUE /bookStore/books/book[2]/title NOK " || l_value CLIPPED) END IF # GET NODE_VALUE: Recupera o valor de determinado nó filho de um nó pai informado. LET l_value = _ADVPL_get_property(l_xml_obj_ref,"NODE_LENGTH","/bookStore/books") IF l_value = 2 THEN CALL CONOUT("LXMLOBJECT GET NODE_LENGTH (/bookStore/books) OK " || l_value CLIPPED) ELSE CALL CONOUT("LXMLOBJECT GET NODE_LENGTH (/bookStore/books) NOK " || l_value CLIPPED) END IF # SET ADD_ATTR: Adiciona um novo atributo no nó informado. CALL _ADVPL_set_property(l_xml_obj_ref,"ADD_ATTR","/bookStore/books/book[1]","isOld","true") LET l_value = _ADVPL_get_property(l_xml_obj_ref,"ATTR_VALUE","/bookStore/books/book[1]","isOld") IF l_value = "true" THEN CALL CONOUT("LXMLOBJECT SET ADD_ATTR (/bookStore/books/book[1] isOld=true) OK " || l_value CLIPPED) ELSE CALL CONOUT("LXMLOBJECT SET ADD_ATTR (/bookStore/books/book[1] isOld=true) NOK " || l_value CLIPPED) END IF # SET ADD_NODE: Adiciona um novo no nó filho no nó pai informado. CALL _ADVPL_set_property(l_xml_obj_ref,"ADD_NODE","/bookStore/books/book[2]","year","1999") LET l_value = _ADVPL_get_property(l_xml_obj_ref,"NODE_VALUE","/bookStore/books/book[2]/year") IF l_value = "1999" THEN CALL CONOUT("LXMLOBJECT SET ADD_NODE (/bookStore/books/book[2] year=1999) OK " || l_value CLIPPED) ELSE CALL CONOUT("LXMLOBJECT SET ADD_NODE (/bookStore/books/book[2] year=1999) NOK " || l_value CLIPPED) END IF # SET ATTR_VALUE: Altera o valor de um atributo do nó informado. CALL _ADVPL_set_property(l_xml_obj_ref,"ATTR_VALUE","/bookStore/books/book[1]","isOld","false") LET l_value = _ADVPL_get_property(l_xml_obj_ref,"ATTR_VALUE","/bookStore/books/book[1]","isOld") IF l_value = "false" THEN CALL CONOUT("LXMLOBJECT SET ATTR_VALUE (/bookStore/books/book[1] isOld=false) OK " || l_value CLIPPED) ELSE CALL CONOUT("LXMLOBJECT SET ATTR_VALUE (/bookStore/books/book[1] isOld=false) NOK " || l_value CLIPPED) END IF # SET NODE_VALUE: Altera o valor de um atributo do nó informado. CALL _ADVPL_set_property(l_xml_obj_ref,"NODE_VALUE","/bookStore/books/book[2]/title","O Alquimista 2") LET l_value = _ADVPL_get_property(l_xml_obj_ref,"NODE_VALUE","/bookStore/books/book[2]/title") IF l_value = "O Alquimista 2" THEN CALL CONOUT("LXMLOBJECT SET NODE_VALUE (/bookStore/books/book[2]/title = 'O Alquimista 2') OK " || l_value CLIPPED) ELSE CALL CONOUT("LXMLOBJECT SET NODE_VALUE (/bookStore/books/book[2]/title = 'O Alquimista 2') NOK " || l_value CLIPPED) END IF # GET SERIALIZE: Tranfere todo conteúdo DO XML para um STRING LET l_xml = _ADVPL_get_property(l_xml_obj_ref,"SERIALIZE") CALL CONOUT("LXMLOBJECT SETGET SERIALIZE: " || l_xml CLIPPED) RETURN TRUE END FUNCTION |
...
Visão Geral
Import HTML Content
Conteúdo das Ferramentas
Tarefas