|
FORUMS PROFESSIONNELS WINDEV, WEBDEV et WINDEV Mobile |
| | | | | |
WM - Exemplo de leitura de um XML com muitos registros |
Débuté par adrianoboller, 21 sep. 2015 19:32 - 6 réponses |
| |
| | | |
|
| |
Membre enregistré 3 657 messages Popularité : +175 (223 votes) |
|
Posté le 21 septembre 2015 - 19:32 |
Procedure ws_mobile_configuracoes( )
ok is boolean
x is int = 0
ChangeCharset(charsetOccidental)
HExecuteQuery(QRY_Delete_ConfigMobile,hQueryDefault)
XML_Retorno is string = ""
RetornoXml is a ws_mobile_configResponse
RetornoXml = ws_mobile_config(2000000,40000000,"SELECT")
XML_Retorno = RetornoXml.ws_mobile_configResult
IF InAndroidSimulatorMode() = True THEN XML_Retorno = UTF8ToAnsi(XML_Retorno,charsetAnsi) END
XmlDoc is XMLDocument
XmlDoc = XMLOpen(XML_Retorno,fromString)
NoXml is xmlNode
FOR EACH NoXml OF XmlDoc.Xml.Retorno on NoXml
x+=1
t010_MobileConfig.t010_Codigo = XmlDoc.Xml.Retorno.NoXml[x].NG0030_Codigo t010_MobileConfig.t010_Descricao = XmlDoc.Xml.Retorno.NoXml[x].NG0030_Descricao t010_MobileConfig.t010_Valor = XmlDoc.Xml.Retorno.NoXml[x].NG0030_Valor t010_MobileConfig.t010_Status = XmlDoc.Xml.Retorno.NoXml[x].NG0030_Status
ok = HAdd(t010_MobileConfig)
END
Info("config: "+x)
HExecuteQuery(QRY_Select_MobileConfig,hQueryDefault) FOR EACH QRY_Select_MobileConfig
END
RESULT(ok)
-- Adriano Jose Boller ______________________________________________ Consultor e Representante Oficial da PcSoft no Brasil +55 (41) 9949 1800 adrianoboller@gmail.com ______________________________________________ |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 3 657 messages Popularité : +175 (223 votes) |
|
Posté le 21 septembre 2015 - 19:33 |
<Xml><Retorno> <NoXml id="1"> <NG0030_Codigo>1</NG0030_Codigo><NG0030_Descricao>VersaoAplicativo</NG0030_Descricao><NG0030_Valor>4738</NG0030_Valor><NG0030_Status>S</NG0030_Status> </NoXml> <NoXml id="2"> <NG0030_Codigo>2</NG0030_Codigo><NG0030_Descricao>MensagemExecutivo</NG0030_Descricao><NG0030_Valor>Veiculos descaracterizados</NG0030_Valor><NG0030_Status>S</NG0030_Status> </NoXml> <NoXml id="3"> <NG0030_Codigo>3</NG0030_Codigo><NG0030_Descricao>MensagemPromocional</NG0030_Descricao><NG0030_Valor>Dia do Pão com Bolinho</NG0030_Valor><NG0030_Status>S</NG0030_Status> </NoXml> <TOTAL>3</TOTAL> </Retorno></Xml>
-- Adriano Jose Boller ______________________________________________ Consultor e Representante Oficial da PcSoft no Brasil +55 (41) 9949 1800 adrianoboller@gmail.com ______________________________________________ |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 3 657 messages Popularité : +175 (223 votes) |
|
Posté le 21 septembre 2015 - 20:35 |
-- Adriano Jose Boller ______________________________________________ Consultor e Representante Oficial da PcSoft no Brasil +55 (41) 9949 1800 adrianoboller@gmail.com ______________________________________________ |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 3 657 messages Popularité : +175 (223 votes) |
|
Posté le 23 septembre 2015 - 17:08 |
Procedure WS_Android_iOs_ReadXml(XML_Retorno is string, Xml_Atributo is string ) IF GloDebugSN = "S" THEN Info("WS_Android_iOs_ReadXml") END
arrXml_TagResult is array of strings xposicaoinicial is int = 0 Xposicaofinal is int = 0 X is int = 0 arrXml_Tag is array of strings XML_Retorno = WS_RemoveAcentos(XML_Retorno) XML_Retorno = Replace(XML_Retorno,CRLF,"") XML_Retorno = Replace(XML_Retorno,CR,"") Inicial is int = PositionOccurrence(XML_Retorno,"<"+Xml_Atributo,firstRank,FromBeginning+IgnoreCase) Final is int = PositionOccurrence(XML_Retorno,"</"+Xml_Atributo+">",lastRank,FromEnd+IgnoreCase) +Length("</"+Xml_Atributo+">") XML_Retorno = Middle(XML_Retorno,Inicial,Final - Inicial) XML_Retorno = Replace(XML_Retorno,Xml_Atributo,"NoXml") XML_Retorno = "<Xml><Retorno>"+XML_Retorno+"</Retorno></Xml>" IF GloDebugSN = "S" THEN Info("recorte",XML_Retorno) END nTotalxml is int = Length(XML_Retorno)
LOOP (nTotalxml)
X++ IFxposicaoinicial = 0 AND Xposicaofinal = 0 AND XML_Retorno[[X]] = "<" THEN X++ IF XML_Retorno[[X]] = "/" THEN xposicaoinicial = X + 1 END END IF xposicaoinicial > 0 AND XML_Retorno[[X]] = ">" THEN Xposicaofinal = X END IF Xposicaofinal > 0 AND xposicaoinicial > 0 THEN stag is string = Middle(XML_Retorno,xposicaoinicial,Xposicaofinal - xposicaoinicial) IF stag="NoXml" THEN BREAK END Add(arrXml_Tag, stag) Xposicaofinal = 0 xposicaoinicial = 0 END
END
IF IniOSMode() = True THEN
NoXml is string i is int = 0 LOOP i++ NoXml = XMLExtractString(XML_Retorno,"NoXml",i) IF NoXml = "" THEN
BREAK
END FOR EACH stag OF arrXml_Tag
temp is string = XMLExtractString(NoXml,stag) Add(arrXml_TagResult, temp )
END END
ELSE IF InAndroidMode() = True
XmlDoc is XMLDocument XmlDoc = XMLOpen(XML_Retorno, fromString) NoXml is xmlNode
FOR EACH NoXml OF XmlDoc.Xml.Retorno on NoXml
FOR EACH sTag OF arrXml_Tag
Add(arrXml_TagResult,NoXml..ChildNode[sTag])
END
END
END
RESULT arrXml_TagResult
-- Adriano Jose Boller ______________________________________________ Consultor e Representante Oficial da PcSoft no Brasil +55 (41) 9949 1800 adrianoboller@gmail.com ______________________________________________ |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 3 657 messages Popularité : +175 (223 votes) |
|
Posté le 23 septembre 2015 - 17:09 |
Procedure WS_Android_IOS_HTTPGetResult()
bufResHTTP is Buffer sHTTPResult is string
bufResHTTP = HTTPGetResult(httpResult)
IF IniOSMode() = True OR IniOSSimulatorMode() = True OR IniOSEmulatorMode() = True IF StringCount(bufResHTTP, “ISO-8859-1”, IgnoreCase) = 0 THEN sHTTPResult = UTF8ToString(bufResHTTP) ELSE sHTTPResult = AnsiToUnicode(bufResHTTP) END ELSE IF InAndroidMode() = True OR InAndroidSimulatorMode() = True OR InAndroidEmulatorMode() = True
sHTTPResult = bufResHTTP END
RESULT sHTTPResult
-- Adriano Jose Boller ______________________________________________ Consultor e Representante Oficial da PcSoft no Brasil +55 (41) 9949 1800 adrianoboller@gmail.com ______________________________________________ |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 3 657 messages Popularité : +175 (223 votes) |
|
Posté le 23 septembre 2015 - 18:10 |
Outro exemplo prático para trabalhar com XML ================================================================
Procedure WS_CartaoCredito()
ok is boolean = False countError is int = 0
IF GloDebugSN = "S" THEN Info ("AtualizaCartaoCredito") END
Retorno is a ws_mobile_cartoes_creditoResponse Retorno = ws_mobile_cartoes_credito(2,0,"SELECT","") XML_Retorno is string = Retorno.ws_mobile_cartoes_creditoResult arrXml_TagResult is array of strings = WS_Android_iOs_ReadXml(XML_Retorno,"NoXml")
IF GloDebugSN = "S" THEN Info (XML_Retorno) END
countItems is int = ArrayCount(arrXml_TagResult) IF countItems > 0 THEN
IF countItems Modulo 4 = 0 THEN Items is int =0
HExecuteQuery(QRY_T019Cartoes_Del)
FOR EACH t019_cartoescreditos HDelete(t019_cartoescreditos) END
WHILE Items < countItems Items++ t019_cartoescreditos.CodigoCartao004 = arrXml_TagResult[Items] Items++ t019_cartoescreditos.Credito004 = arrXml_TagResult[Items] Items++ t019_cartoescreditos.NomeCartao004 = arrXml_TagResult[Items] Items++ t019_cartoescreditos.DataHoraUltimaAlteracao004 = arrXml_TagResult[Items] t019_cartoescreditos.DataAtualizacao004 = DateSys() ok = HAdd(t019_cartoescreditos) IF ok = False THEN countError++ ELSE IF GloDebugSN = "S" THEN Info("Adicionado com sucesso") END END
END
END
END
IF countError > 0 THEN ok = False END
RESULT ok
-- Adriano Jose Boller ______________________________________________ Consultor e Representante Oficial da PcSoft no Brasil +55 (41) 9949 1800 adrianoboller@gmail.com ______________________________________________ |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 3 657 messages Popularité : +175 (223 votes) |
|
Posté le 23 septembre 2015 - 18:34 |
-- Adriano Jose Boller ______________________________________________ Consultor e Representante Oficial da PcSoft no Brasil +55 (41) 9949 1800 adrianoboller@gmail.com ______________________________________________ |
| |
| |
| | | |
|
| | | | |
| | |
| | |
| |
|
|
|