• 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: Convert NSXMLDocument to a NSDictionary?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert NSXMLDocument to a NSDictionary?


  • Subject: Re: Convert NSXMLDocument to a NSDictionary?
  • From: "Lorenzo Thurman" <email@hidden>
  • Date: Mon, 16 Apr 2007 15:10:45 -0500 (CDT)
  • Importance: Normal

> On Apr 14, 2007, at 1:30 PM, Lorenzo Thurman wrote:
>
>> Is there a simple way of doing this? Cocoa does not seem to provide a
>> method for doing this, at least nothing within either class seems to
>> fit
>> the fit the bill.
>
> Your question doesn't really make sense as stated.  You can treat an
> XML property list as a dictionary, since that's really what it's a
> representation of, but for arbitrary XML there really can't be any
> dictionary representation because Cocoa couldn't know (unless you
> supplied it with a schema mapping somehow) how to represent the items
> in the XML document as generic property list objects.
>
> That's why NSXMLDocument exists, and is as complex as it is:  It is a
> full-fidelity representation of the XML document as a tree of
> NSXMLNode and NSXMLElement instances, which you can traverse and
> modify as appropriate for your needs.  If you need to transform it
> into a dictionary according to some rules, you need to write the code
> to implement that transformation.
Thanks for the reply. I've figured it out. Not being familiar with XML, my
question was as malformed as an XML document w/o its header. I understand
that the structure is similar to a hash, dictionary, associative array,
etc. Not knowing any better, I hoped that converting it to a NSDictionary
would make it easier to access its key/value pairs, but of course, there's
the key's attributes. So xml=>NSDictionary would be more trouble than it's
worth.
I found XQuery (and XPath), and that gives me the kind of access quite
similar to what I would have with a NSDictionary, plus accessing
attributes is made as trivial as accessing the key/value pairs.
Thanks again
>
>    -- Chris
>
>


--
"Remember...a good friend will help you move. A realy good friend will
help you move a body."
-Unknown


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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

References: 
 >Convert NSXMLDocument to a NSDictionary? (From: Lorenzo Thurman <email@hidden>)
 >Re: Convert NSXMLDocument to a NSDictionary? (From: Chris Hanson <email@hidden>)

  • Prev by Date: Import sqlite data file
  • Next by Date: Re: Import sqlite data file
  • Previous by thread: Re: Convert NSXMLDocument to a NSDictionary?
  • Next by thread: Re: Convert NSXMLDocument to a NSDictionary?
  • Index(es):
    • Date
    • Thread