[Gambas-user] Reading XML Attributes.

Caveat Gambas at ...1950...
Wed Mar 30 19:44:26 CEST 2011


Hi Antonio

I think this is the result you're looking for:

*******************************************************************************************
Get the Attribute "type" from the path wireless-network
Using full path: /wireless-network
Attribute key: number
Attribute key: type
infrastructure
****************************************************************************************


Using the general purpose xml editor I'm developing, you only need 3
lines of code to get your type attribute:

  parserToModel.parseInputFile("wireless-network.xml")n
  rewriter = NEW XMLRewriter(parserToModel.getModel())
  PRINT rewriter.getAttribute("/wireless-network", "type")

I posted the project on this mailing list a while back.  The code you
need would appear to be something like this (last 3 or 4 lines get the
attributes):

  IF reader.Node.Type = XmlReaderNodeType.Element THEN 
    'Logger.logMessage("Got a start element for: " & reader.Node.Name,
FALSE)
    newBucket = NEW XMLContainer
    newBucket.setNodeName(reader.Node.Name)
    IF currentBucket = NULL THEN 
      newBucket.setPathToNode("/")
    ELSE 
      newBucket.setPathToNode(currentBucket.getFullPath())
    END IF
    'Logger.logMessage("[NODE: " & newBucket.getFullPath() & "]" " node
name: " & newBucket.getNodeName(), FALSE)
    FOR EACH reader.Node.Attributes
      newBucket.setAttribute(reader.Node.Name, reader.Node.Value)
    NEXT

The reader object is a standard XmlReader.

Let me know if I need to repost the project.

Regards,
Caveat

On Wed, 2011-03-30 at 17:21 +0100, Antonio Cassidy wrote:
> Hi All
> 
> I am trying to write a gambas application to parse kismet XML logs.
> 
> I am able to parse elements and also sub elements but not the attributes.
> 
> My code is here:
> http://pastebin.com/QiX2BsHH
> 
> The sample XML is here, i specifically want to get the "type" attribute from
> the "wireless-network" element
> http://pastebin.com/4DGwdzYD
> 
> Many thanks
> ------------------------------------------------------------------------------
> Create and publish websites with WebMatrix
> Use the most popular FREE web apps or write code yourself; 
> WebMatrix provides all the features you need to develop and 
> publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user






More information about the User mailing list