0

I'm reading a plist using simplexml_load_file the plist I have opens as checked using var_dump however I'm not sure of the syntax to actually access the items. All i need to get is 2 pieces of info.

The var_dump from simplexml_load_file looks like the below. All i want is the text "SimpleCalculator"

object(SimpleXMLElement)#1 (2) {
  ["@attributes"]=>
  array(1) {
    ["version"]=>
    string(3) "3.0"
  }
  ["dict"]=>
  object(SimpleXMLElement)#2 (2) {
    ["key"]=>
    string(5) "items"
    ["array"]=>
    object(SimpleXMLElement)#3 (1) {
      ["dict"]=>
      object(SimpleXMLElement)#4 (3) {
        ["key"]=>
        array(2) {
          [0]=>
          string(6) "assets"
          [1]=>
          string(8) "metadata"
        }
        ["array"]=>
        object(SimpleXMLElement)#5 (1) {
          ["dict"]=>
          object(SimpleXMLElement)#7 (2) {
            ["key"]=>
            array(2) {
              [0]=>
              string(4) "kind"
              [1]=>
              string(3) "url"
            }
            ["string"]=>
            array(2) {
              [0]=>
              string(16) "software-package"
              [1]=>
              string(7) "__URL__"
            }
          }
        }
        ["dict"]=>
        object(SimpleXMLElement)#6 (2) {
          ["key"]=>
          array(5) {
            [0]=>
            string(17) "bundle-identifier"
            [1]=>
            string(14) "bundle-version"
            [2]=>
            string(4) "kind"
            [3]=>
            string(5) "title"
            [4]=>
            string(8) "subtitle"
          }
          ["string"]=>
          array(5) {
            [0]=>
            string(16) "SimpleCalculator"
            [1]=>
            string(3) "000"
            [2]=>
            string(8) "software"
            [3]=>
            string(33) "com.mywork.demo"
            [4]=>
            string(3) "1.0"
          }
        }
      }
    }
  }
}

And the XML Looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="3.0">
<dict>
    <key>items</key>
    <array>
        <dict>
            <key>assets</key>
            <array>
                <dict>
                    <key>kind</key>
                    <string>software-package</string>
                    <key>url</key>
                    <string>__URL__</string>
                </dict>
            </array>
            <key>metadata</key>
            <dict>
                <key>bundle-identifier</key>
                <string>SimpleCalculator</string>
                <key>bundle-version</key>
                <string>000</string>
                <key>kind</key>
                <string>software</string>
                <key>title</key>
                <string>com.mywork.demo</string>
                <key>subtitle</key>
                <string>1.0</string>
            </dict>
        </dict>
    </array>
</dict>
</plist>
4

1 回答 1

3

Tested and Works.

<?php
if (file_exists('test.xml')) {
    $xml = simplexml_load_file('test.xml');

    echo $xml->dict->array->dict->dict->string;//Simple Calculator

} else {
    exit('Failed to open test.xml.');
}

编辑 :

你需要像这样循环

echo $xml->dict->array->dict->dict->string[0];//Simple Calculator
echo $xml->dict->array->dict->dict->string[1];//000
echo $xml->dict->array->dict->dict->string[2];//software
于 2013-09-19T11:59:59.327 回答