views:

69

answers:

1

I've been searching for about two hours now trying to find out what this error is and how to solve it. Apple's documents gladly says

NSXMLParserAttributeNotStartedError Attribute is not started. Available in Mac OS X v10.3 and later. Declared in NSXMLParser.h.

but fails to provide any help whatsoever. Can anyone help me out here? Any nudge in the right direction is greatly appreciated.

In viewDidLoad, I have:

NSURL *xmlUrl = [NSURL fileURLWithPath:xmlFilepath];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlUrl];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities:NO];
BOOL success = [xmlParser parse];

No problems with getting the xml, I can successfully read up until the root element, then it breaks.

The rest of the related code goes like:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
 if([elementName isEqualToString:@"foo"]) {
  foo = [[NSMutableArray alloc] init];
 } else if([elementName isEqualToString:@"bar"]) {
  bar = [[Bar alloc] init];
 }
}

- (void)parser:(NSXMLParser *)parser foundAttributeDeclarationWithName:(NSString *)attributeName forElement:(NSString *)elementName type:(NSString *)type defaultValue:(NSString *)defaultValue {
  if ([elementName isEqualToString:@"bar"]) {
  if ([attributeName isEqualToString:@"barAttrib1"]) {
   [bar setBarAttrib1:[defaultValue intValue]];
  } else if ([attributeName isEqualToString:@"barAttrib2"]) {
   [bar setBarAttrib2:defaultValue];
  } 
 }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
 // nothing inside the elements, just attributes
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
 if ([elementName isEqualToString:@"bar"]) {  
  [foo addObject:bar];  
  [bar release];
  bar = nil;
 }
}

Thanks in advance.

EDIT: example xml

<foo>
  <bar barAttrib1=1 barAttrib2="hello" />
  <bar barAttrib1=2 barAttrib2="world" />
</foo>
+2  A: 

If this is XML, then quotes are REQUIRED around the attribute value. Try

<foo>
  <bar barAttrib1="1" barAttrib2="hello" />
  <bar barAttrib1="2" barAttrib2="world" />
</foo>

Note the quotes around the values of barAttrib1

Jim Garrison
arr... But of course. >.<I must be way too stressed out that I overlooked that. I'll try that once I get back to the office tomorrow. Thanks!
Altealice
Yep, that did it. Thanks Jim!
Altealice