[Gambas-user] xmlreader

gaupe hennie at ...1826...
Fri Jan 4 21:36:12 CET 2008



Thank you very much. 
This was just the example i needed.
I overlooked some in another code somewhere else but now i see how its done!
have a sample code working for me thats reads out the lat and lon from the
example and see now how i can read the rest.
 So can finally use this to read my xml (gpx) files

(And throw away my selfwritten ,textfile readthrough ,find string, extract
string, compare string, monster.)

for those who struggle with the same and want a simple example
put code down here in a module and startup the module

PUBLIC SUB main()
xmlwrite()
XmlRead()
END



' Gambas module file
PUBLIC SUB xmlwrite()
   DIM xml AS xmlwriter
   xml = NEW xmlwriter
   xml.Open("test.xml", TRUE, "UTF-8")
   xml.StartElement("wpt", ["lat", "60.1419274", "lon", "11.1703764"])
   xml.EndElement() ' End wpt
   xml.EndDocument()
END

PUBLIC SUB xmlread()

   DIM xml AS NEW XmlReader
   DIM xmlstring, Selement, sAttribute, sValue AS String
   DIM Lat, lon AS String
   DIM myColumnsTyp AS NEW String[]
   DIM myColumnsVisible AS NEW Byte[]

   
   xmlString = file.Load("test.xml")
   Xml = NEW XmlReader
   Xml.FromString(xmlString)
   WHILE NOT Xml.Eof
      SELECT CASE Xml.Node.Type
         CASE XmlReaderNodeType.Element
            sElement = Xml.Node.Name
            PRINT Selement
            IF Upper(Trim(sElement)) = Upper("Wpt") THEN
               FOR EACH Xml.Node.Attributes
                  sAttribute = xml.Node.Name
                  sValue = Xml.Node.Value
                  PRINT sAttribute
                  IF Upper(sAttribute) = Upper("Lat") THEN
                     Lat = Svalue
                     PRINT lat
                  ELSE IF Upper(sAttribute) = Upper("Lon") THEN
                     Lon = Svalue
                     PRINT lon
                  ENDIF
                NEXT
             ENDIF
      END SELECT
      xml.Read()
   WEND   
END

-- 
View this message in context: http://www.nabble.com/xmlreader-tp14617540p14624380.html
Sent from the gambas-user mailing list archive at Nabble.com.





More information about the User mailing list