B4J Question Parse XML

victormedranop

Well-Known Member
Licensed User
Longtime User
I have 2 days trying to parse some XML string. Try XML2MAP and the old way with parse.
some assistance.
this is the xml
B4X:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><AutorizaJugadaXmlResponse xmlns="http://tempuri.org/"><AutorizaJugadaXmlResult><![CDATA[<?xml version="1.0"?><RespuestaAuth><Autorizacion>038080C9-2943-46BF-3F1FCB7793</Autorizacion><Referencia>4EAEAE34-D602-477B-8AE8-F6284E50908A</Referencia><NumeroTicketPozo>479</NumeroTicketPozo><CodResp>0</CodResp><DescResp>Operacion Satisfactoria</DescResp></RespuestaAuth>]]></AutorizaJugadaXmlResult></AutorizaJugadaXmlResponse></s:Body></s:Envelope>

was using this code

B4X:
  parser.Initialize
  Dim in As InputStream
  Dim b() As Byte
  b = j.GetString.GetBytes("UTF8")
  in.InitializeFromBytesArray(b,0,b.Length)
  parser.Parse(in,"Parser")


Sub Parser_StartElement (Uri As String, Name As String, Attributes As Attributes)
End Sub
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
' Log($"${Uri}  ${Name}  ${Text}"$)
 If parser.Parents.IndexOf("RespuestaAuth") > -1 Then
  Log("llego algo")
  If Name = "Autorizacion" Then
   Log (Text.ToString)
  Else If Name = "Referencia" Then
   Log(Text.ToString)
  Else If Name = "NumeroTicketPozo" Then
   Log(Text.ToString)
  End If
 End If
End Sub
 

victormedranop

Well-Known Member
Licensed User
Longtime User
solve.
need to parse 2 times. if some one have a better way please share.

victor

B4X:
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
' Log("HAY ALGO XML RESPONSE?? :"&parser.Parents.IndexOf("AutorizaJugadaXmlResponse"))
 If parser.Parents.IndexOf("AutorizaJugadaXmlResponse") > -1 Then
  Log(Text.ToString)
  parser2.Initialize
  Dim in As InputStream
  Dim b() As Byte
  b = Text.ToString.GetBytes("UTF8")
  in.InitializeFromBytesArray(b,0,b.Length)
  parser2.Parse(in,"Parser2")
 End If
End Sub

Sub Parser2_EndElement (Uri As String, Name As String, Text As StringBuilder)
' Log("Parse 2 name :"& Name &" data:  "&Text.ToString)
' Log("HAY ALGO Respuesta Auth?? :"&parser2.Parents.IndexOf("RespuestaAuth"))
 If parser2.Parents.IndexOf("RespuestaAuth") > -1 Then
  If Name = "Autorizacion" Then 
   Log(Text.ToString)
  End If 
 End If
End Sub
[code]
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
There can't be a better idea as the XML document includes another embedded XML document.
I have a method to receive in json, but first I have to decode the XML structure.
this people are insane.

but customer always win.

victor
 
Upvote 0
Top