Re: Event-Driven XML Parsing and Entity References
Re: Event-Driven XML Parsing and Entity References
- Subject: Re: Event-Driven XML Parsing and Entity References
- From: "Carter R. Harrison" <email@hidden>
- Date: Mon, 28 Jul 2008 14:27:40 -0400
On Jul 27, 2008, at 5:13 PM, Nathan Kinsinger wrote:
On Jul 27, 2008, at 12:52 PM, Carter R. Harrison wrote:
There's been some discussion on this topic previously, but I
haven't been able to find the solution that I'm looking for. I'm
using the event-driven XML parser (CFXMLParser). Apparently it
does not support the replacement of entity references (&, <,
>, etc..).
So assume I'm trying to parse the following XML tag:
<title>Planes, Trains, & Automobiles</title>
When the parser enters the <title> node, it calls the
createStructure callback function three times. Each time it has
the following data within the node that is passed in:
Call #1: "Planes, Trains, "
Call #2: "&"
Call #3: " Automobiles"
A similar thing happens in the addChild callback function.
I understand that I need to do manual replacement of the & with
a "&" in this case, but I still don't understand how I'm supposed
to maintain the state in between the three calls to createStructure
and addChild so that I can successfully concatenate all three text
segments together to form the original string (which is what I want
to store). I hope this makes sense - it's terribly frustrating.
As always, thanks in advance.
I haven't used CFXMLParser, but generally in event xml parsing you
keep adding to the string until the end of the element. Parsers may
break the element up into several parts and give them to you one at
a time.
Ya, I finally got fed up with the Core Foundation parser and switched
to the Cocoa Event Driven parser. The cocoa parser works like you
have just mentioned, but after going through all the Docs on the Core
Foundation parser it appears to be different. I don't know why I
didn't go with Cocoa in the first place. As soon as I decided to use
the cocoa parser I had everything working perfectly within 3 minutes!
Thanks for the help.
In this case in either your addChild or createStructure functions
you would add the new parsed string to the child nodes existing
string.
You may find more people with experience using CFXMLParser on the
Carbon dev list:
http://lists.apple.com/mailman/listinfo/carbon-dev
That said, this is the Cocoa dev list, have you looked at NSXMLParser?
http://developer.apple.com/documentation/Cocoa/Conceptual/XMLParsing/XMLParsing.html
--Nathan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden