Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing Mac XML PList into something readable
    primarykey
    data
    text
    <p>I am trying to pull data from <a href="http://en.wikipedia.org/wiki/XML" rel="nofollow noreferrer">XML</a> <a href="https://en.wikipedia.org/wiki/Property_list" rel="nofollow noreferrer">PList</a> (<a href="https://en.wikipedia.org/wiki/System_Information" rel="nofollow noreferrer">Apple System Profiler</a>) files, and read it into a memory database, and finally I want to turn it into something human-readable. </p> <p>The problem is that the format seems to be very difficult to read in a consistent manner. I have gone over a few solutions already, but I haven't found a solution yet that I found satisfying. I always end up having to hard code a lot of values, and end up having to many <code>if-else/switch statements</code>. </p> <p><strong>The format looks like this.</strong> </p> <pre><code>&lt;plist&gt; &lt;key&gt;_system&lt;/key&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;_cpu_type&lt;/key&gt; &lt;string&gt;Intel Core Duo&lt;/string&gt; &lt;/dict&gt; &lt;/array&gt; &lt;/plist&gt; </code></pre> <p>Example file <a href="http://pastebin.com/X9Z0KGdH" rel="nofollow noreferrer">here</a>.</p> <p>After I have read (or during reading), I make use of an internal dictionary that I use to determine what type of information it is. For example, if the key is <code>cpu_type</code> I save the information accordingly. </p> <hr> <p>A few examples that I have tried (<code>simplified</code>) to pull the information. </p> <pre><code> XmlTextReader reader = new XmlTextReader("C:\\test.spx"); reader.XmlResolver = null; reader.ReadStartElement("plist"); String key = String.Empty; String str = String.Empty; Int32 Index = 0; while (reader.Read()) { if (reader.LocalName == "key") { Index++; key = reader.ReadString(); } else if (reader.LocalName == "string") { str = reader.ReadString(); if (key != String.Empty) { dct.Add(Index, new KeyPair(key, str)); key = String.Empty; } } } </code></pre> <p>Or something like this.</p> <pre><code>foreach (var d in xdoc.Root.Elements("plist")) dict.Add(d.Element("key").Value,&gt; d.Element("string").Value); </code></pre> <p>I found a framework, that I may be able to modify <a href="http://code.google.com/p/iphone-plist-net/" rel="nofollow noreferrer">here</a>.</p> <hr> <p><strong>Some more useful information</strong></p> <p>Mac OS X Information on the system profiler <a href="http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/system_profiler.8.html" rel="nofollow noreferrer">here</a>.</p> <p>Apple script used to parse the XML-files <a href="http://macscripter.net/viewtopic.php?id=19190" rel="nofollow noreferrer">here</a>.</p> <hr> <p>Any advise or insight into this would be deeply appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload