Re: A strange constructor question
Re: A strange constructor question
- Subject: Re: A strange constructor question
- From: Jamie <email@hidden>
- Date: Mon, 21 Jun 2004 13:15:12 +0100
OK
I got that. I have implemented both those methods already, as it is
necessary to do so for the parser to work. I guess your idea will
work, but it just means I have some unneeded instance variables at the
end. I perhaps need to look at variable scope so I can make them
private to the instance so as not to confuse the interface to the
class.
Thanks for your help.
Jamie
PS - You should make sure you respond to the list address too, so that
others can benefit from the answer you give. :)
On 21 Jun 2004, at 13:04, Daniel Eggert wrote:
Seems like I got something wrong... sorry.
The way I see it, your delegate should handle both
parser:didStartElement:namespaceURI:qualifiedName:attributes:
and
parser:didEndElement:namespaceURI:qualifiedName:
Check out the description at
http://developer.apple.com/documentation/Cocoa/Conceptual/XMLParsing/
You should put you elements of type 'file' into an instance variable
(NSMutableArray) 'currentFile' and when it ends convert it into an
NSArray and put that array into the enclosing (NSMutableDictionary)
'currentData' element. Once that 'data' element ends convert it into
an NSDictionary. You're set.
/Daniel
On Jun 21, 2004, at 1:40 PM, Jamie wrote:
Thanks for your response.
On 21 Jun 2004, at 12:28, Daniel Eggert wrote:
I may be missing something here, but why doesn't the call that
creates the NSDictionary itself create its child nodes (NSArrays) to
hook them up with the dictionary?
Because the NSArray's need to be referred to over several calls to
the function. They are constructed in this way, so I cannot simply
create and assign them in one call. The children of the NSDictionary
(the arrays) should ideally not be separate instance variables that
can be referred to as such, and also should not be mutable. The only
way i can think of doing it _is_ to make mutable arrays as instance
variables, so that I can refer to them over several function calls.
That is: The NSDictionary _is_ initialised in one function call,
since that function call will can itself to grab onto those
children.
Don't quite get the way you phrased that. Could you expand?
Jamie
On Jun 21, 2004, at 11:45 AM, Jamie wrote:
Hi there.
I mailed a few days ago explaining that I was working on a project
which initialises various objects by becoming the delegate for an
NSXMLParser.
I have now hit what seems to me to be a difficult design issue.
Basically I have an object that is initialising it's instance
variables using the XMLParser by repeatedly calling
- (void) parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
and dealing with each of the relevant elements in turn. The
problem is that this is not all done during one call to the
function, but over multiple iterations, therefore it makes it
impossible to use things such as an NSDictionary to hold some of
the values. Let me explain in more detail:
The object in question describes a software suite, and has instance
variables such as "Name", "Blurb" etc... It also has to hold data
about the various locations of it's data items (files and folders
associated with it). So in the XML config file, under the relevant
section I have a section called "data". Under that there is a list
of child elements, either <folder> or <file> elements.
What I wanted to to was to have an NSDictionary called "data" as an
instance variable of the object. This would in turn hold two
NSArray's, one called "files" and one called "folders". Each array
would be populated in turn with the relevant information from the
configuration file.
This would work fine if the NSDictionary was initialised from one
function call, since I could build two mutable array's, convert the
to normal arrays, and assign them to an NDDictionary. Over
multiple calls however, this is not possible, since I cannot make
the temporary mutable array's local variables in the mehtod. They
must be instance variables instead, and it seems to me I have to
write some very complicated accessors to make this structure
feasible.
Am I going about this the wrong way, or is this the only way to get
things done in this case?
Many thanks for your thoughts.
--
jkp
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: PGP 8.0.3
mQGiBEAvrCkRBADP0l+qGhYxe7VZe8NhHPvHKGfYEzMg/FpZxqRY179JI2EAPM4P
ojR8YuTmFDEPgz+4Ae4IUIJyhJBean5D/CFy3TpHYTUlK3eA1cH7PDNOW7oTGSmM
+zRkD1HnkaPVwylmNvI4RmceA0JuhCi9Y35Bkxa1yBLLB+uRC1Zf4+Ek/QCg/4Jh
161Ewn5UOV2eAmxFFRmyCLsD/jCeNrU4w5i/8YLoVFy3vZYhNsPL299vNc/PmF+h
+NPbbWAgay2UVnyc0lkbtOr+ZiEjgf0ltr3rDrjaF6faxwo8sDE5Tuh1yUUJ5Ngv
VLgyDLn9ChnOxiKYGZeI173JXYYhk3V8eU8qtIdH+IBQeHJjeWJg4dKRNqqDzlaI
r3GmA/9S11g+wKWYwKUNbPqRp29KuiRkINV34EXjAdK20kwb3misSt1x86xUHslq
Egys6T7Ulw1bAFKAWnm4pddv0khVx95reQlk/pIJZym26QSdXORPIjJ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
=/4Ed
-----END PGP PUBLIC KEY BLOCK-----
_______________________________________________
MacOSX-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/macosx-dev
_______________________________________________
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.