• 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
Re: Help with CFXML?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with CFXML?


  • Subject: Re: Help with CFXML?
  • From: Chris Parker <email@hidden>
  • Date: Thu, 14 Mar 2002 01:54:42 -0800

Hi Lucas,

On Thursday, March 14, 2002, at 12:51 AM, Lucas Haley wrote:

Heya -- I am trying to read in an XML file into my app, and am having
difficulties making a CFXMLTree. The call to
"CFXMLTreeCreateFromData" doesn't return anything. Can anyone spot my
mistake? Thank you so much for any help

Lucas
(a newbie)

My loading code looks like:

- (void)loadFromData: (NSData *)theData
{
CFXMLTreeRef myXMLTree, myMovingTree;
CFXMLNodeRef xmlNode;
NSString *s;

NSLog(@"The Data: %@\n", theData);

// Fill out the XML Tree
if (!theData)
{
return;
} else {
myXMLTree = CFXMLTreeCreateFromData(kCFAllocatorSystemDefault,
theData, NULL, kCFXMLParserSkipWhitespace, kCFXMLNodeCurrentVersion);

Well, what you probably wanted here is

myXMLTree = CFXMLTreeCreateFromData(kCFAllocatorDefault, theData, NULL, kCFXMLParserSkipWhitespace, kCFXMLNodeCurrentVersion);

The header files warn against using the system allocator directly (see CFBase.h). This isn't really the problem though:

It looks like you're using the CFXMLTreeCreateFromData call correctly - the real question is: how sure are you of your XML? If for some reason it's malformed (missing an end tag, etc.) the parser that's hiding behind CFXMLTreeCreateFromData will cause it to bail on the parse and hand you back a NULL. The high-level tree parser doesn't give you a whole lot of feedback about what went wrong - just that something did. You may wish to drop down and use the lower level parser to better capture error conditions.

I'd probably feed the XML to a validator on the web and see if it trips over anything.

.chris

--
Chris Parker
Cocoa Frameworks Engineer
_______________________________________________
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.

References: 
 >Help with CFXML? (From: Lucas Haley <email@hidden>)

  • Prev by Date: NSAutoreleasePool problem
  • Next by Date: Re: NSAutoreleasePool problem
  • Previous by thread: Help with CFXML?
  • Next by thread: Using NSCell with NSTableView
  • Index(es):
    • Date
    • Thread