Diferencia entre revisiones de «Gambas/Manipular documentos XML»

Contenido eliminado Contenido añadido
Línea 83:
The easiest way to read a XML document is using the XmlReader class that allow to navigate thru the document by moving forward a pull parser over each node; and allow know the name, type and value of each node. The way it works is inside a loop and repeatedly call the Read() method to retrieve the parsing events; then the parser descent recursively to reflect the structure of the XML document being parsed.
Now, you’ll create an application to read the XML file you just created and with the info contained on it populate a Tree View control. You’ll start a new graphical application project called ReadXML and create the following controls with their settings. Don’t forget to include the gb.xml component.
Table IV-8. ReadXML widgets and settings
Widget
Property
Línea 96 ⟶ 95:
DIM reader AS XmlReader
reader = NEW XmlReader
TRY reader.Open(User.home & "/Heroes.xml")
IF ERROR THEN
Línea 163 ⟶ 161:
IF ERROR THEN BREAK
LOOP
ReadXML must look like this.
 
[[Archivo:ReadXML.png]]
 
If the previous example still kind of confusing probably you must try to understand first how the Read() parser moves over the XML structure. Add a new button, and include the following code and compare the output on the console against the content of the XML file.
DIM reader AS XmlReader
reader = NEW XmlReader
TRY reader.Open(User.home & "/Heroes.xml")
IF ERROR THEN
Línea 174 ⟶ 173:
RETURN
ENDIF
 
DO WHILE TRUE
TRY reader.Read()