PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → Solution to XML Reurn Chines em HttpRequest e HttpGetResult
Solution to XML Reurn Chines em HttpRequest e HttpGetResult
Débuté par adrianoboller, 18 nov. 2014 18:56 - 16 réponses
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 18 novembre 2014 - 18:56
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
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 18 novembre 2014 - 18:57
Procedure WS_Android_iOs_ReadXml(XML_Retorno is string, Xml_Atributo is string )

//Exemplo de Uso:
// XML_Retorno 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>
// ]
//
// 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

Inicial is int = PositionOccurrence(XML_Retorno,"<"+Xml_Atributo,firstRank,FromBeginning)
Final is int = PositionOccurrence(XML_Retorno,"</"+Xml_Atributo+">",lastRank,FromEnd) +Length("</"+Xml_Atributo+">")
XML_Retorno = Middle(XML_Retorno,Inicial,Final - Inicial)
XML_Retorno = Replace(XML_Retorno,Xml_Atributo,"NoXml")
XML_Retorno = "<Xml><Recorte>"+XML_Retorno+"</Recorte></Xml>"

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

//iOS - Apple (iPhone / iPad / iPod)
IF IniOSMode() = True THEN

NoXml is string
i is int = 1
NoXml = XMLExtractString(XML_Retorno,"NoXml",i)

FOR EACH stag OF arrXml_Tag

temp is string = XMLExtractString(NoXml,stag)
Add(arrXml_TagResult, temp )

END

//Android
ELSE IF InAndroidMode() = True

XmlDoc is XMLDocument
XmlDoc = XMLOpen(XML_Retorno, fromString)
NoXml is xmlNode

FOR EACH NoXml OF XmlDoc.Xml.Recorte on NoXml

FOR EACH sTag OF arrXml_Tag

Add(arrXml_TagResult,NoXml..ChildNode[sTag])

END

END

END

RESULT arrXml_TagResult
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 18 novembre 2014 - 18:58
ok = HTTPRequest("http://"+IpSaladaFruta01+"/soap/IRtPlusSSDM","", "", Xml_SEND, "text/xml","","")

IF ok = True

//HTTPGetResult

XML_Retorno = WS_Android_IOS_HTTPGetResult()

XML_Retorno = Capitalize(WS_RemoveAcentos(XML_Retorno))

IF DebugSN = "S" THEN
Info("/mnt/sdcard/TaxiFv/Arquivos/RetornoPosicaoTaxi.TXT", XML_Retorno)
IF InAndroidMode() = True
IF InSimulatorMode() = False
fSaveBuffer("/mnt/sdcard/TaxiFv/Arquivos/RetornoPosicaoTaxi.TXT", XML_Retorno)
ELSE
fSaveBuffer("c:\RetornoPosicaoTaxi.TXT", XML_Retorno)
END
END
END
END
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 18 novembre 2014 - 19:13
Ansi x Unicode
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 18 novembre 2014 - 19:37


Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 18 novembre 2014 - 19:40
OBS.:

The Android and iOS project while using this configuration is that the global definition of the project and the button: "Describing the current configuration" which is at the bottom of the screen.
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 18 novembre 2014 - 20:14
"Describing the current configuration"
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 05 décembre 2014 - 08:48
Adriano
On page http://forum.pcsoft.fr/fr-FR/pcsoft.fr.windevmobile/18410-qui-maitrise-utf8-ansi-unicode/read.awp

it is written:
4) I integrate the text file into my table by reading fOpen()

and this is what was the problem for me for my text file geonames
I try UTF8ToString() AnsiVersUnicode() and UnicodeToAnsi() without result

A you try with a text file containing Greek characters, Chinese, Japanese, Hebrew or Latin characters not?
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 09 décembre 2014 - 17:56
IF StringCount(bufResHTTP, “ISO-8859-1,IgnoreCase) =0 THEN
sHTTPResult=UTF8ToString(bufResHTTP)
ELSE
sHTTPResult=AnsiToUnicode(bufResHTTP)
END
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 09 décembre 2014 - 18:01
I work only with Latin characters without Chinese characters or umlauts.

Use this function here:

Return_Json = NoAccent(Return_Json)

And

http://forum.pcsoft.fr/fr-FR/pcsoft.us.windevmobile/959-remove-acento-961/read.awp
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 29 janvier 2015 - 12:52
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
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 25 mai 2015 - 21:09
:merci:
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 26 mai 2015 - 19:19
/////// para ler o arquivo em Unicode gerado por um app feito em Windev Mobile para Android ou iOS

MyUnicodeString is UNICODE string
sLine is string = ""
sTextFileUnicode is string = "c:\tmp\00010101.txt"// formato Unicode
mLinha is string

// aqui coloquei o parametro "foAnsi"

MyUnicodeString = fLoadText(sTextFileUnicode,foAnsi)// carregar o texto

// aqui coloquei o parametro "charsetAnsi"

sLine = UnicodeToAnsi(MyUnicodeString,charsetAnsi)// converter o texto

ListDeleteAll(ListBox1)
ListAdd(ListBox1,sLine)// jogar o texto convertido em um ListBox

FOR EACH ROW OF ListBox1// ler linha a linha e tratá-la de acordo com as suas regras
mLinha = ListBox1..DisplayedValue// receber o conteudo de cada linha do texto
Trace(mLinha)// visualizar o conteudo lido em mLinha para efeito didático apenas
END

////////////////// FIM //////////////////

// para gravar o arquivo em unicode por um app iOS/Android feito em Windev Mobile

xFLagOk is boolean
FileID is int = fCreate(DirPadrao+mArquivo,foAnsi) // aqui coloquei o parametro "foAnsi"
IF FileID=-1 THEN
Info("Erro ao criar arquivo.")
xFlagOk=False
RETURN
END

... // ponha o seu codigo aqui
... // ponha o seu código aqui

// aqui coloquei o parâmetro ftpASCIIMode

EnviarArquivo is boolean=FTPSend(MinhaConexao,DirPadrao+mArquivo,CompleteDir(xPastaPedidos),"",ftpASCIIMode)
IF EnviarArquivo=False THEN
Error("Erro ao enviar arquivo para o FTP.",ErrorInfo())
Info("Arquivo não foi enviado.","Tente enviá-lo novamente.")
xFlagOk=False
RETURN
END
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 26 mai 2015 - 19:20
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 19 septembre 2015 - 21:25
OBS. : E se ainda tiver problemas use antes de qualquer codigo esse comando:

ChangeCharset(charsetOccidental) // SEM ACENTO


--
Adriano Jose Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
______________________________________________