XQuery string help

  • As a result of an earlier post/answer I got an XML-string into an
    NSXMLDocument object. Now I'm trying to search through the xml and
    find the elements that I want to use in my code. For example in this
    bit of XML here I want to search through the Array and find every
    instance to retrieve their name and url. Preferably I would like to
    store all the found element stringvalues in an array.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd
    ">
    <plist version='1.0'>
        <dict>
          <key>group</key>
          <array>
            <dict>
              <key>name</key>
              <string>Person1</string>
              <key>uuid</key>
              <string>663D73DA-2BAF-477C-9D09-E9DC851081A3</string>
              <key>url</key>
              <string>www.someurl.com</string>
            </dict>
            <dict>
              <key>name</key>
              <string>Person2</string>
              <key>uuid</key>
              <string>463A75BAE-2CBA-437D-1E04-F91EC1673445</string>
              <key>url</key>
              <string>www.someurl.com</string>
            </dict>
          </array>
        </dict>
      </plist>

    I've been trying to use [NSXMLDocument objectsForXQuery:@".//
    something" error:&myError]; but I can't seem to figure out the right
    xquery-string to find the objects.

    Marcel
  • On 25/10/2007, at 8:38 AM, Marcel Borsten wrote:

    > As a result of an earlier post/answer I got an XML-string into an
    > NSXMLDocument object. Now I'm trying to search through the xml and
    > find the elements that I want to use in my code. For example in
    > this bit of XML here I want to search through the Array and find
    > every instance to retrieve their name and url. Preferably I would
    > like to store all the found element stringvalues in an array.

    Since your document is a property list, why not load it as a property
    list and then do whatever you need to do that way?

    - Chris
  • On 10/24/07, Marcel Borsten <marcel...> wrote:

    > <?xml version="1.0" encoding="UTF-8"?>
    > <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd
    > ">
    > <plist version='1.0'>
    > <dict>
    > <key>group</key>
    > <array>
    > <dict>
    > <key>name</key>
    > <string>Person1</string>
    > <key>uuid</key>
    > <string>663D73DA-2BAF-477C-9D09-E9DC851081A3</string>
    > <key>url</key>
    > <string>www.someurl.com</string>
    > </dict>
    > <dict>
    > <key>name</key>
    > <string>Person2</string>
    > <key>uuid</key>
    > <string>463A75BAE-2CBA-437D-1E04-F91EC1673445</string>
    > <key>url</key>
    > <string>www.someurl.com</string>
    > </dict>
    > </array>
    > </dict>
    > </plist>

    Not sure how to do what you want with NSXMLDocument (never tried the
    query functionality)... but what you posted above is a plist. So using
    +[NSPropertyListSerialization
    propertyListFromData:mutabilityOption:format:errorDescription:] you
    can turn the above into Cocoa collection objects.

    In the case of the above you would get back reference to an
    NSDictionary with a key of "group" that references an NSArray instance
    that contained NSDictionary instances (etc.).

    -Shawn
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today