The examples in this section demonstrate how to parse a simple XML document using each of the Core Foundation XML Services parser APIs.
The document shown in Listing 1-3 contains the XML representation of a very simple Core Foundation property list created using Property List Services. Note that a property list was chosen purely for the purposes of illustrating XML parser usage in a Core Foundation context. The Property List Services API has convenience functions for converting property lists to and from XML format, so in most cases your application would not need to parse an XML property list using the XML parser directly.
Listing 1-3 A Core Foundation property list in XML format
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/ PropertyList.dtd"> <plist version="0.9"> <dict> <key>Jane Doe</key> <integer>1999</integer> <key>John Doe</key> <integer>2000</integer> </dict> </plist>
In this example XML document, the data consists of two names and associated birth years. The
<plist>
tag declares that the enclosed data is a property list that corresponds to the Core Foundation data type CFPropertyList. The
<dict>
tag declares that its enclosed data corresponds to a CFDictionary. Finally, the name and birth year data are listed in the key/value pair format required for a CFDictionary.