[Gambas-user] XML Question

Ron Onstenk ronstk at ...239...
Sun Nov 14 05:38:29 CET 2004


I try to get a xml file in a treeview

First I see the nodes same as a directory
children are the sub directories.
The attributes should come in a list as name/value pairs
when I select a node and the text element(s) is a second list.

My xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<kwintv version="1" >
 <tvregion>
  <info>
   <name></name>
   <norm></norm>
  </info>
  <channels>
   <channel enabled="true" >
    <name>Nederland 1</name>
    <encoding>pal</encoding>
    <source>television</source>
    <number>1</number>
    <frequency>216000</frequency>
   </channel>
   <channel enabled="true" >
    <name>Nederland 2</name>
    <encoding>pal</encoding>
    <source>television</source>
    <number>2</number>
    <frequency>184000</frequency>
   </channel>
  </channels>
 </tvregion>
</kwintv>

When I print the node.name of the first node I itterate I get kwintv
for the node.value I get the whole text content of all the nodes.
It has however 1 attibute, named version.

I call a sub to show the attributes of a node.
--------------
PUBLIC SUB showdatr(dnode AS XmlNode,ind AS Integer)
  
  DIM i AS Integer
  DIM s AS String
  DIM sa AS String[]
  DIM o AS XmlReaderNodeType
  DIM n AS XmlNode
  
  i=dnode.Attributes.Count
  IF i>0 THEN

    FOR i = 0 TO dnode.Attributes.Count-1
    
'      s =dnode.Attributes[i]  ' it say's 'not a array' but has 1 entry so must be array
'      sa=dnode.Attributes[i]  ' it say's 'not a array' but has 1 entry so must be array
'      s =dnode.Attributes     ' expect string, got .XmlNodeAttributes 
   
'      PRINT Space(ind+2) & "attribute:";i,dnode.Attributes 'say (XmlNode 0x8146120)

' why is the type here XmlNode and before .XmlNodeAttributes?
' XmlNodeAttributes has only a count but no name/value pairs
 
' ok n=xmlnode and has name/value pairs
''  n=dnode.Attributes 'bad class
''  PRINT Space(ind+2) & "attributename:";i,n.Name
''  PRINT Space(ind+2) & "attributevalue:";i,n.Value

  PRINT Space(ind+2) & "attributename:";i,dnode.Attributes.Name 'say .XmlNodeAttributes 
  PRINT Space(ind+2) & "attributevalue:";i,dnode.Attributes.Value 'say .XmlNodeAttributes
 
    NEXT
     
  ELSE
    PRINT Space(ind+2) & "attribute:none"
  ENDIF  
   
END
--------------

when i use   n=dnode.Attributes[i] i got message it is not a array
How do I get the attrributes, I'm lost now.

If I can get help how to iterate the nodes and get the attributes
I'm will be happy, I have no luck.


In the XMLnode are many constants. They tell me something about a 
node or attribute type but there is no property for Type.

















More information about the User mailing list