discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GSXML


From: Nicola Pero
Subject: Re: GSXML
Date: Mon, 20 May 2002 14:54:56 +0100 (BST)

> I have to say that in that case I don't know what on earth you are 
> talking about.

My pleasure - try the following code -

#include <Foundation/Foundation.h>
#include <Foundation/GSXML.h>

/* Parse a NSString, returning the root node as parsed.  */
GSXMLNode *rootNode (NSString *string)
{
  NSData *data = [string dataUsingEncoding: NSUTF8StringEncoding];
  GSXMLParser *parser = [GSXMLParser parser];
  if ([parser parse: data] == NO)
    {
      NSLog (@"Couldn't parse");
      return nil;
    }
  return [[parser doc] root];
}

int main (void)
{
  CREATE_AUTORELEASE_POOL (pool);

  /* The string we want to parse.  */
  NSString *string = @"<?xml version=\"1.0\"?><test></test>";

  /* Parse the document and get the root node for later printing.  */
  GSXMLNode *root = rootNode (string);

  /* Retain it because we need it later.  */
  RETAIN (root);

  /* The GUI automatically recreates autorelease pools regularly,
   * so let's simulate what happens in any running GUI program.  */
  DESTROY (pool);
  pool = [NSAutoreleasePool new];
  
  /* Now print out the details of the parsed root node.  */
  NSLog (@"Content is :");
  NSLog ([root content]);

  NSLog (@"Attributes are :");
  NSLog ([[root propertiesAsDictionary] description]);

  DESTROY (pool);
  
  return 0;
}

If you have been able to use non-SAX GSXML for anything serious - you
lucky.  I haven't.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]