PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → XML read
XML read
Débuté par marcov, 29 déc. 2020 11:56 - 5 réponses
Membre enregistré
55 messages
Posté le 29 décembre 2020 - 11:56
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
Posté le 21 janvier 2021 - 11:27
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")
Membre enregistré
30 messages
Posté le 21 janvier 2021 - 11:31
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")
Membre enregistré
30 messages
Posté le 21 janvier 2021 - 11:34
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
Membre enregistré
30 messages
Posté le 21 janvier 2021 - 11:35
i is int
FOR i= 1 TO icount
Trace(XMLRead("XMLSuppliers","/dataroot/suppliers/id[" + i + "]" ) + TAB + XMLRead("XMLSuppliers","/dataroot/suppliers/description[" + i + "]") )
END
Membre enregistré
55 messages
Posté le 29 janvier 2021 - 12:54
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