[Gambas-user] xmlreader
Charlie Reinl
Karl.Reinl at ...9...
Fri Jan 4 20:30:35 CET 2008
Am Freitag, den 04.01.2008, 06:36 -0800 schrieb gaupe:
> using Gambas2.0
>
> I am still having problems reading back xmldata i wrote
> I cant find out how to read back the attributes lat lon
> how is that done?
>
> (the example does not produce very much valid xml but its more for the
> example)
>
> please let me know also if i am doing it SO wrong thats answering is
> hopeless...... ;-)
>
> from test.xml
>
> 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
Salut,
send you some code and 2 XML files, out of an project, who use these to
populate a Grid(TableView).
This is out from an Gambas1 project
FUNCTION LoadData(sKey AS String) AS Boolean
DIM bRet AS Boolean
DIM Xml AS XmlReader
DIM xmlString AS String
DIM sElement AS String
DIM sAttribute AS String
DIM sValue AS String
DIM myText AS NEW String[]
DIM myFields AS NEW String[]
DIM myColumnsTyp AS NEW String[]
DIM myColumnsVisible AS NEW Byte[]
xmlString = file.Load(Application.Path &/ sKey & ".xml")
Xml = NEW XmlReader
Xml.FromString(xmlString)
WHILE NOT Xml.Eof
SELECT CASE Xml.Node.Type
CASE XmlReaderNodeType.Element
sElement = Xml.Node.Name
IF Upper(Trim(sElement)) = Upper("Column") THEN
FOR EACH Xml.Node.Attributes
sAttribute = xml.Node.Name
sValue = Xml.Node.Value
IF Upper(sAttribute) = Upper("ColID") THEN
' iColumn = CInt(Xml.Node.Value)
ELSE IF Upper(sAttribute) = Upper("Header") THEN
myText.Add(sValue)
ELSE IF Upper(sAttribute) = Upper("Field") THEN
myFields.Add(sValue)
ELSE IF Upper(sAttribute) = Upper("Typ") THEN
myColumnsTyp.Add(sValue)
ELSE IF Upper(sAttribute) = Upper("Visible")
THEN
myColumnsVisible.Add(CByte(sValue))
ENDIF
NEXT
ENDIF
END SELECT
Xml.Read()
WEND
' ME.DataColumnsText = myText
' ME.DataColumnsFields = myFields
' ME.DataColumnsTyp = myColumnsTyp
' ME.DataColumnsVisible = myColumnsVisible
bRet = TRUE
FINALLY
RETURN bRet
CATCH
bRet = FALSE
END
--
Amicalment
Charlie
-------------- next part --------------
A non-text attachment was scrubbed...
Name: USERS.xml
Type: application/xml
Size: 911 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20080104/4ea7fa65/attachment.xml>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CUST.xml
Type: application/xml
Size: 598 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20080104/4ea7fa65/attachment-0001.xml>
More information about the User
mailing list