PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV 2024 → XML read
XML read
Iniciado por marcov, dez., 29 2020 11:56 AM - 5 respostas
Membro registado
55 mensagems
Publicado em dezembro, 29 2020 - 11:56 AM
hi,
how can i read an xml received from a socket?
Actually I get the answer formatted in xml but if I have to understand the content of an element, do I have to write the xml file to read it?

vOpensend is Variant

vOpensend= XMLBuildString(OpenRic,XMLNoHeader)

SocketWrite("BC",vOpensend)

vOpenRis is xmlDocument
vOpenRis= XMLOpen(SocketRead("BC",False,8000))

now vOpenRis is my xml but how can I access the data?
THANKS
Publicado em janeiro, 21 2021 - 11:27 AM
i save the xml to file from the response and after read it like this
i use the xmlpath to read the data for more complex xml


<?xml version="1.0" encoding="UTF-8"?>
<dataroot>
<suppliers>
<id>0</id>
<description>testsupplier0</description>
<id>1</id>
<description>testsupplier1</description>
</suppliers>
</dataroot>


xml_path is UNICODE string
xml_path = fExeDir() + "\Suppliers.xml"
Trace(xml_path)
Myxmldoc is string = fLoadText(xml_path)
IF ErrorOccurred = True THEN
Info(ErrorInfo,"4")
END

XMLDocument( "XMLSuppliers" , Myxmldoc)

IF ErrorOccurred = True THEN
Info(ErrorInfo,"5")
END

Trace("----------------------------")
icount is int
XMLSuppliers is xmlDocument
XMLSuppliers=XMLOpen(Myxmldoc,fromString)
id is xmlNode
FOR EACH id OF XMLSuppliers.dataroot.suppliers on id
Trace("id for count :"+ id) // //value to count or we can read data on this node
icount++
END

i is int
FOR i= 1 TO icount
Trace(XMLRead("XMLSuppliers","/dataroot/suppliers/id[" + i + "]" ) + TAB + XMLRead("XMLSuppliers","/dataroot/suppliers/description[" + i + "]") )
i ++
Trace(XMLRead("XMLSuppliers","/dataroot/suppliers/id[" + i + "]" ) + TAB + XMLRead("XMLSuppliers","/dataroot/suppliers/description[" + i + "]") )
END
Trace("----------------------------")

XMLClose("XMLSuppliers")
Membro registado
30 mensagems
Publicado em janeiro, 21 2021 - 11:31 AM
i save the xml to file from the response and after read it like this
i use the xmlpath to read the data for more complex xml


<?xml version="1.0" encoding="UTF-8"?>
<dataroot>
<suppliers>
<id>0</id>
<description>testsupplier0</description>
<id>1</id>
<description>testsupplier1</description>
</suppliers>
</dataroot>


xml_path is UNICODE string
xml_path = fExeDir() + "\Suppliers.xml"
Trace(xml_path)
Myxmldoc is string = fLoadText(xml_path)
IF ErrorOccurred = True THEN
Info(ErrorInfo,"4")
END

XMLDocument( "XMLSuppliers" , Myxmldoc)

IF ErrorOccurred = True THEN
Info(ErrorInfo,"5")
END

Trace("----------------------------")
icount is int
XMLSuppliers is xmlDocument
XMLSuppliers=XMLOpen(Myxmldoc,fromString)
id is xmlNode
FOR EACH id OF XMLSuppliers.dataroot.suppliers on id
Trace("id for count :"+ id) // //value to count or we can read data on this node
icount++
END

i is int
FOR i= 1 TO icount
Trace(XMLRead("XMLSuppliers","/dataroot/suppliers/id[" + i + "]" ) + TAB + XMLRead("XMLSuppliers","/dataroot/suppliers/description[" + i + "]") )
i ++
Trace(XMLRead("XMLSuppliers","/dataroot/suppliers/id[" + i + "]" ) + TAB + XMLRead("XMLSuppliers","/dataroot/suppliers/description[" + i + "]") )
END
Trace("----------------------------")

XMLClose("XMLSuppliers")
Membro registado
30 mensagems
Publicado em janeiro, 21 2021 - 11:34 AM
edit remove i++

i is int
FOR i= 1 TO icount
Trace(XMLRead("XMLSuppliers","/dataroot/suppliers/id[" + i + "]" ) + TAB + XMLRead("XMLSuppliers","/dataroot/suppliers/description[" + i + "]") )
Trace(XMLRead("XMLSuppliers","/dataroot/suppliers/id[" + i + "]" ) + TAB + XMLRead("XMLSuppliers","/dataroot/suppliers/description[" + i + "]") )
END
Membro registado
30 mensagems
Publicado em janeiro, 21 2021 - 11:35 AM
i is int
FOR i= 1 TO icount
Trace(XMLRead("XMLSuppliers","/dataroot/suppliers/id[" + i + "]" ) + TAB + XMLRead("XMLSuppliers","/dataroot/suppliers/description[" + i + "]") )
END
Membro registado
55 mensagems
Publicado em janeiro, 29 2021 - 12:54 PM
hi,
i solved it with this simple syntax

vValRisp is xmlDocument
vValRisp= XMLOpen(AnsiToUnicode(SocketRead("BC",False,8000),charsetAnsi))

dabruciare.sCodeline=EDT_Codeline
dabruciare.sResultcode=vValRisp.CRQ.LIST.ELEM.OPRES