• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
declaring a global variable.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

declaring a global variable.


  • Subject: declaring a global variable.
  • From: Sing Li <email@hidden>
  • Date: Mon, 22 Mar 2004 18:01:54 -0500

hi all,

I am trying to use OmniExpat to parse my xml string and since it is
using SAX, I need to store the data in an array.

i have 2 files - XmlHandler.h and XmlHandler.m see following.

This is my error output:
XmlHandler.m:44: error: `ma' undeclared (first use in this function)
XmlHandler.m:44: error: (Each undeclared identifier is reported only
once
XmlHandler.m:44: error: for each function it appears in.)

So how can i declare a global variable?

//
// XmlHandler.h
// NSMovie_Example
//
// Created by sli on Fri Mar 19 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <OmniFoundation/OmniFoundation.h>
#import <OmniExpat/OmniExpat.h>
#import <OmniExpat/xmlparse.h>


@interface XmlHandler : NSObject
{

@public
NSDictionary *d;
NSMutableArray *ma;

}
- (void)parseXml: (NSString*)content;
@end


//
// XmlHandler.m
// NSMovie_Example
//
// Created by sli on Fri Mar 19 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//

// XmlHandler.m
#import "XmlHandler.h"

void handleStartElement(void *userData, const char *name, const char
**attributes);
void handleEndElement(void *userData, const char *name);
void handleCharacters(void *userData, const char *data, int len);

@implementation XmlHandler

- (void)parseXml: (NSString*)content
{
ma = [NSMutableArray array];

XML_Parser parser = XML_ParserCreate("UTF-8");
XML_SetElementHandler(parser, handleStartElement, handleEndElement);
XML_SetCharacterDataHandler(parser, handleCharacters);

if (XML_Parse(parser, [content UTF8String], [content length], YES )
== 0)
{
int errorCode = XML_GetErrorCode(parser);
int lineNumber = XML_GetCurrentLineNumber(parser);
const char* errorDescription = XML_ErrorString(errorCode);
NSLog(@"Parse Failure, code: %d, line: %d, description: %s",
errorCode, lineNumber, errorDescription);

XML_ParserFree(parser);
}

XML_ParserFree(parser);
}

void handleStartElement(void *userData, const char *name, const char
**attributes)
{

NSString* elementName = [NSString stringWithUTF8String:name];
NSLog(@"Start> %@",elementName);
[ma addObject:elementName]; //<- problem

if (*attributes)
{
char **attributeNameIndex;

/* Step to next key/value pair */
for (attributeNameIndex = attributes; *attributeNameIndex !=
NULL; attributeNameIndex += 2 )
{
NSString *attributeName = [NSString
stringWithCString:*attributeNameIndex];
NSString *attributeValue = [NSString
stringWithCString:*(attributeNameIndex + 1)];

NSLog(@"Attribute> %@=%@",attributeName,attributeValue);
}
}
}

void handleEndElement(void *userData, const char *name)
{
NSString* elementName = [NSString stringWithUTF8String:name];
NSLog(@"end> %@",elementName);
}

void handleCharacters(void *userData, const char *data, int len)
{
NSData *utf8Data = [NSData dataWithBytes:data length:len];
NSString *dataString = [[[NSString alloc] initWithData:utf8Data
encoding:NSUTF8StringEncoding] autorelease];

NSLog(@"CData=%@",dataString);
}

@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Re: Graphite examples ??
  • Next by Date: copyPath:toPath:handler: sometimes it works, sometimes it does not?
  • Previous by thread: Re: Auto-scrolling
  • Next by thread: copyPath:toPath:handler: sometimes it works, sometimes it does not?
  • Index(es):
    • Date
    • Thread