PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 24 → WM - Exemplo de leitura de um XML com muitos registros
WM - Exemplo de leitura de um XML com muitos registros
Débuté par adrianoboller, 21 sep. 2015 19:32 - 6 réponses
Membre enregistré
2 907 messages
Popularité : +89 (91 votes)
Posté le 21 septembre 2015 - 19:32
Procedure ws_mobile_configuracoes( )

ok is boolean

x is int = 0

ChangeCharset(charsetOccidental) // SEM ACENTO

//Limpa tabela local
HExecuteQuery(QRY_Delete_ConfigMobile,hQueryDefault)

//Webservice Consumo
//############################################################################
XML_Retorno is string = ""

RetornoXml is a ws_mobile_configResponse

RetornoXml = ws_mobile_config(2000000,40000000,"SELECT")

XML_Retorno = RetornoXml.ws_mobile_configResult

//Para testar no emulador
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

// [x] é o nó a ser lido do xml ou registro

ok = HAdd(t010_MobileConfig)//adição dos dados na tabela local

END

Info("config: "+x) //registros lidos

HExecuteQuery(QRY_Select_MobileConfig,hQueryDefault) //inicializa a query
FOR EACH QRY_Select_MobileConfig
//leitura dos registrosInfo(QRY_Select_MobileConfig.t010_Codigo,QRY_Select_MobileConfig.t010_Descricao,QRY_Select_MobileConfig.t010_Valor,QRY_Select_MobileConfig.t010_Status)
END

RESULT(ok)


--
Adriano Jose Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
______________________________________________
Membre enregistré
2 907 messages
Popularité : +89 (91 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é
2 907 messages
Popularité : +89 (91 votes)
Posté le 21 septembre 2015 - 20:35
:merci:

--
Adriano Jose Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
______________________________________________
Membre enregistré
2 907 messages
Popularité : +89 (91 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
//Exemplo de Uso:
// sXML_Retornox is string = [
//<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
//xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
//xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
//<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
//xmlns:NS1="urn:act297_RtPlusSSDM-IRtPlusSSDM">
//<NS1:VerificarVersaoDeTabelasResponse xmlns:NS2="urn:act297_RtPlusSSDM">
//<NS2:TVersaoTabelas id="1" xsi:type="NS2:TVersaoTabelas">
//<datHoraMotivos xsi:type="xsd:string">2013-07-11T17:15:33</datHoraMotivos>
//<qtdMotivos xsi:type="xsd:int">3</qtdMotivos>
//<datHoraCartoes xsi:type="xsd:string">2013-07-01T12:00:00</datHoraCartoes>
//<qtdCartoes xsi:type="xsd:int">6</qtdCartoes>
//<datHoraPesquisa xsi:type="xsd:string">2013-07-10T12:14:42</datHoraPesquisa>
//<qtdPesquisa xsi:type="xsd:int">4</qtdPesquisa>
//</NS2:TVersaoTabelas>
//<return href="#1"/>
//</NS1:VerificarVersaoDeTabelasResponse>
//</SOAP-ENV:Body>
//</SOAP-ENV:Envelope>
// ]
//
// XML_Retorno = sXML_Retornox
//
// Uso da Funcao:+-+-
//arrTemp is array of strings = WS_Android_iOs_ReadXml(XML_Retorno,"NS2:TVersaoTabelas")

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
//info("count tags ",ArrayCount(arrXml_Tag))
//iOS - Apple (iPhone / iPad / iPod)
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

//Android
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é
2 907 messages
Popularité : +89 (91 votes)
Posté le 23 septembre 2015 - 17:09
Procedure WS_Android_IOS_HTTPGetResult()

// Variable
bufResHTTP is Buffer
sHTTPResult is string

// Retrieves the result of the query
bufResHTTP = HTTPGetResult(httpResult)

// Result in UTF8 em iOS Apple
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
// Result in Android
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é
2 907 messages
Popularité : +89 (91 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

//Webservice
//---------------------------------------------------------------------------------------------
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é
2 907 messages
Popularité : +89 (91 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
______________________________________________