<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PHP plist parsing</title>
	<atom:link href="http://blog.iconara.net/2007/05/08/php-plist-parsing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/</link>
	<description></description>
	<lastBuildDate>Mon, 07 Nov 2011 12:03:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: KT</title>
		<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/comment-page-1/#comment-8486</link>
		<dc:creator>KT</dc:creator>
		<pubDate>Sat, 18 Dec 2010 00:41:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2007/05/08/php-plist-parsing/#comment-8486</guid>
		<description>&lt;p&gt;Theo,&lt;/p&gt;

&lt;p&gt;Thanks for the excellent example. I worked your code, with a few minor tewaks, into a standalone class in case anyone else finds it useful&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;read_file($inPath);&lt;/p&gt;

&lt;p&gt;// Class definition
class PListFile
{
    function read_file($inPath)
    {
        $document = new DOMDocument();
        $document-&gt;load($inPath);&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    return $this-&gt;parse_plist($document);
}

function parse_plist($inDocument) 
{
    $docNode = $inDocument-&gt;documentElement;
    $root    = $docNode-&gt;firstChild;

    // skip any text nodes before the first value node
    while ( $root-&gt;nodeName == &quot;#text&quot; ) 
    {
        $root = $root-&gt;nextSibling;
    }

    return $this-&gt;parse_node($root);
}

function parse_node( $inNode ) 
{
    $valueType  = strtolower($inNode-&gt;nodeName);
    $selector   = &#039;parse_&#039;.$valueType;

    return $this-&gt;$selector($inNode);
}

function parse_array( $inNode ) 
{
    $array = array();

    for ( $node = $inNode-&gt;firstChild; $node != null; $node = $node-&gt;nextSibling ) 
    {
        if ( $node-&gt;nodeType == XML_ELEMENT_NODE ) 
        {
            $array[] = $this-&gt;parse_node($node);
        }
    }

    return $array;
}

function parse_dict( $inNode ) 
{
    $dict = array();

    // for each child of this node
    for ( $node = $inNode-&gt;firstChild; $node != null; $node = $node-&gt;nextSibling ) 
    {
        if ( $node-&gt;nodeName == &quot;key&quot; ) 
        {
            $key        = $node-&gt;textContent;
            $valueNode  = $node-&gt;nextSibling;

            // skip text nodes
            while ( $valueNode-&gt;nodeType == XML_TEXT_NODE ) 
            {
                $valueNode = $valueNode-&gt;nextSibling;
            }

            // recursively parse the children
            $value = $this-&gt;parse_node($valueNode);

            $dict[$key] = $value;
        }
    }

    return $dict;
}

function parse_integer( $inNode ) 
{
    return $inNode-&gt;textContent;
}

function parse_real( $inNode ) 
{
    return $inNode-&gt;textContent;
}

function parse_string( $inNode ) 
{
    return $inNode-&gt;textContent;  
}

function parse_date( $inNode ) 
{
    return $inNode-&gt;textContent;
}

function parse_true( $inNode ) 
{
    return true;
}

function parse_false( $inNode ) 
{
    return false;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;}
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Theo,</p>

<p>Thanks for the excellent example. I worked your code, with a few minor tewaks, into a standalone class in case anyone else finds it useful</p>

<p><pre><code>read_file($inPath);</code></pre></p>

<p>// Class definition
class PListFile
{
    function read_file($inPath)
    {
        $document = new DOMDocument();
        $document-&gt;load($inPath);</p>

<pre><code>    return $this-&amp;gt;parse_plist($document);
}

function parse_plist($inDocument) 
{
    $docNode = $inDocument-&amp;gt;documentElement;
    $root    = $docNode-&amp;gt;firstChild;

    // skip any text nodes before the first value node
    while ( $root-&amp;gt;nodeName == "#text" ) 
    {
        $root = $root-&amp;gt;nextSibling;
    }

    return $this-&amp;gt;parse_node($root);
}

function parse_node( $inNode ) 
{
    $valueType  = strtolower($inNode-&amp;gt;nodeName);
    $selector   = 'parse_'.$valueType;

    return $this-&amp;gt;$selector($inNode);
}

function parse_array( $inNode ) 
{
    $array = array();

    for ( $node = $inNode-&amp;gt;firstChild; $node != null; $node = $node-&amp;gt;nextSibling ) 
    {
        if ( $node-&amp;gt;nodeType == XML_ELEMENT_NODE ) 
        {
            $array[] = $this-&amp;gt;parse_node($node);
        }
    }

    return $array;
}

function parse_dict( $inNode ) 
{
    $dict = array();

    // for each child of this node
    for ( $node = $inNode-&amp;gt;firstChild; $node != null; $node = $node-&amp;gt;nextSibling ) 
    {
        if ( $node-&amp;gt;nodeName == "key" ) 
        {
            $key        = $node-&amp;gt;textContent;
            $valueNode  = $node-&amp;gt;nextSibling;

            // skip text nodes
            while ( $valueNode-&amp;gt;nodeType == XML_TEXT_NODE ) 
            {
                $valueNode = $valueNode-&amp;gt;nextSibling;
            }

            // recursively parse the children
            $value = $this-&amp;gt;parse_node($valueNode);

            $dict[$key] = $value;
        }
    }

    return $dict;
}

function parse_integer( $inNode ) 
{
    return $inNode-&amp;gt;textContent;
}

function parse_real( $inNode ) 
{
    return $inNode-&amp;gt;textContent;
}

function parse_string( $inNode ) 
{
    return $inNode-&amp;gt;textContent;  
}

function parse_date( $inNode ) 
{
    return $inNode-&amp;gt;textContent;
}

function parse_true( $inNode ) 
{
    return true;
}

function parse_false( $inNode ) 
{
    return false;
}
</code></pre>

<p>}
</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/comment-page-1/#comment-7936</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Sun, 25 Oct 2009 20:25:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2007/05/08/php-plist-parsing/#comment-7936</guid>
		<description>&lt;p&gt;@john: what you&#039;re asking for is exactly what&#039;s under the &quot;Wrapping it up&quot; header.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@john: what you&#8217;re asking for is exactly what&#8217;s under the &#8220;Wrapping it up&#8221; header.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: john freeman</title>
		<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/comment-page-1/#comment-7935</link>
		<dc:creator>john freeman</dc:creator>
		<pubDate>Sat, 24 Oct 2009 21:55:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2007/05/08/php-plist-parsing/#comment-7935</guid>
		<description>&lt;p&gt;the comment above mine - from CFPropertyList, was EXACTLY what I was looking for, so thanks for getting my to where I want to be!&lt;/p&gt;

&lt;p&gt;jf&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>the comment above mine &#8211; from CFPropertyList, was EXACTLY what I was looking for, so thanks for getting my to where I want to be!</p>

<p>jf</p>]]></content:encoded>
	</item>
	<item>
		<title>By: john freeman</title>
		<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/comment-page-1/#comment-7934</link>
		<dc:creator>john freeman</dc:creator>
		<pubDate>Sat, 24 Oct 2009 21:07:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2007/05/08/php-plist-parsing/#comment-7934</guid>
		<description>&lt;p&gt;hi,&lt;/p&gt;

&lt;p&gt;This almost useful post is missing a crucial piece of information (for me anyway) - namely, how to do the iteration of the file to get the DOMElement objects.&lt;/p&gt;

&lt;p&gt;I&#039;ve been messing with reading RSS files, and they have a nice hierarchical structure, but Mac PLists (AlbumData) have this &quot;key-value&quot; pair structure that I came to your page to the hope of finding a good way to deal with.  I will keep looking!&lt;/p&gt;

&lt;p&gt;thanks!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>hi,</p>

<p>This almost useful post is missing a crucial piece of information (for me anyway) &#8211; namely, how to do the iteration of the file to get the DOMElement objects.</p>

<p>I&#8217;ve been messing with reading RSS files, and they have a nice hierarchical structure, but Mac PLists (AlbumData) have this &#8220;key-value&#8221; pair structure that I came to your page to the hope of finding a good way to deal with.  I will keep looking!</p>

<p>thanks!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: CFPropertyList</title>
		<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/comment-page-1/#comment-7827</link>
		<dc:creator>CFPropertyList</dc:creator>
		<pubDate>Tue, 19 May 2009 14:49:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2007/05/08/php-plist-parsing/#comment-7827</guid>
		<description>&lt;p&gt;“The PHP implementation of Apple’s PropertyList can handle XML PropertyLists as well as binary PropertyLists. It offers functionality to easily convert data between worlds, e.g. recalculating timestamps from unix epoch to apple epoch and vice versa. A feature to automagically create (guess) the plist structure from a normal PHP data structure will help you dump your data to plist in no time.”&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>“The PHP implementation of Apple’s PropertyList can handle XML PropertyLists as well as binary PropertyLists. It offers functionality to easily convert data between worlds, e.g. recalculating timestamps from unix epoch to apple epoch and vice versa. A feature to automagically create (guess) the plist structure from a normal PHP data structure will help you dump your data to plist in no time.”</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/comment-page-1/#comment-6817</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Wed, 04 Jun 2008 11:27:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2007/05/08/php-plist-parsing/#comment-6817</guid>
		<description>&lt;p&gt;print_r($array);&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>print_r($array);</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Philip Brechler</title>
		<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/comment-page-1/#comment-6816</link>
		<dc:creator>Philip Brechler</dc:creator>
		<pubDate>Wed, 04 Jun 2008 08:36:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2007/05/08/php-plist-parsing/#comment-6816</guid>
		<description>&lt;p&gt;Thanks!&lt;/p&gt;

&lt;p&gt;I tried it on another server, it works fine now. But what can I search for? If I do a echo count ( $array ); its allways 0. So if parse for &quot;serialNumber&quot; or such it should find something or is there a error in my thougts?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks!</p>

<p>I tried it on another server, it works fine now. But what can I search for? If I do a echo count ( $array ); its allways 0. So if parse for &#8220;serialNumber&#8221; or such it should find something or is there a error in my thougts?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/comment-page-1/#comment-6815</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Wed, 04 Jun 2008 06:12:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2007/05/08/php-plist-parsing/#comment-6815</guid>
		<description>&lt;p&gt;I have no idea. Check your error log. It could be a number of things that has gone wrong. For one it&#039;s possible that your PHP installation doesn&#039;t have DOM support.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I have no idea. Check your error log. It could be a number of things that has gone wrong. For one it&#8217;s possible that your PHP installation doesn&#8217;t have DOM support.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Philip Brechler</title>
		<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/comment-page-1/#comment-6814</link>
		<dc:creator>Philip Brechler</dc:creator>
		<pubDate>Tue, 03 Jun 2008 22:42:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2007/05/08/php-plist-parsing/#comment-6814</guid>
		<description>&lt;p&gt;Hi!&lt;/p&gt;

&lt;p&gt;I would like to use your script to parse trough a system profile of OS X clients. But after this:&lt;/p&gt;

&lt;p&gt;$plistDocument = new DOMDocument();
$plistDocument-&gt;load($path);&lt;/p&gt;

&lt;p&gt;the scipt stops without a error notification. What is the meaning of this?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi!</p>

<p>I would like to use your script to parse trough a system profile of OS X clients. But after this:</p>

<p>$plistDocument = new DOMDocument();
$plistDocument-&gt;load($path);</p>

<p>the scipt stops without a error notification. What is the meaning of this?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://blog.iconara.net/2007/05/08/php-plist-parsing/comment-page-1/#comment-5871</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Tue, 01 Apr 2008 16:02:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2007/05/08/php-plist-parsing/#comment-5871</guid>
		<description>&lt;p&gt;It would work fine in PHP5. I&#039;m pretty sure I tested it on a PHP5 system (can&#039;t remember when I last worked on a PHP4 system).&lt;/p&gt;

&lt;p&gt;You can even stick the functions inside a class, but then you would have to change this part:&lt;/p&gt;

&lt;p&gt;if ( is_callable($transformerName) ) {
  return call_user_func($transformerName, $valueNode);
}&lt;/p&gt;

&lt;p&gt;into something like this:&lt;/p&gt;

&lt;p&gt;if ( is_callable(array($this, $transformerName)) ) {
  return $this-&gt;$transformerName($valueNode);
}&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>It would work fine in PHP5. I&#8217;m pretty sure I tested it on a PHP5 system (can&#8217;t remember when I last worked on a PHP4 system).</p>

<p>You can even stick the functions inside a class, but then you would have to change this part:</p>

<p>if ( is_callable($transformerName) ) {
  return call_user_func($transformerName, $valueNode);
}</p>

<p>into something like this:</p>

<p>if ( is_callable(array($this, $transformerName)) ) {
  return $this->$transformerName($valueNode);
}</p>]]></content:encoded>
	</item>
</channel>
</rss>

