Page 1 of 1

Acces XML data

Posted: Sat Mar 20, 2010 10:01 am
by iLdn
I have to extract data from this XML file

Code: Select all

 
<?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="1.0">
<dict>
   <key>CFBundleDevelopmentRegion</key>
   <string>English</string>
   <key>CFBundleDisplayName</key>
   <string>ASPHALT4</string>
   <key>CFBundleExecutable</key>
   <string>ASPHALT4</string>
   <key>CFBundleIconFile</key>
   <string>icon.png</string>
   <key>CFBundleIdentifier</key>
   <string>com.gameloft.ASPHALT4</string>
   <key>CFBundleInfoDictionaryVersion</key>
   <string>6.0</string>
   <key>CFBundlePackageType</key>
   <string>APPL</string>
   <key>CFBundleResourceSpecification</key>
   <string>ResourceRules.plist</string>
   <key>CFBundleVersion</key>
   <string>1.3.8</string>
   <key>DTPlatformName</key>
   <string>iphoneos</string>
   <key>DTSDKName</key>
   <string>iphoneos2.1</string>
   <key>MinimumOSVersion</key>
   <string>2.1</string>
   <key>SignerIdentity</key>
   <string>Apple iPhone OS Application Signing</string>
   <key>UIStatusBarHidden</key>
   <true/>
</dict>
</plist>
 
 
as you can see the tags are all the same: key and string. How can the value of BundleDisplayName be extracted?

Re: Acces XML data

Posted: Sat Mar 20, 2010 12:14 pm
by John Cartwright

Code: Select all

$xmlRoot = simplexml_load_string($your_xml_string);
 
foreach($xmlRoot->dict as $val){
   echo $val->getName() .' = '. $val .'<br />';
}
?

Re: Acces XML data

Posted: Sat Mar 20, 2010 12:29 pm
by iLdn
John Cartwright wrote:

Code: Select all

$xmlRoot = simplexml_load_string($your_xml_string);
 
foreach($xmlRoot->dict as $val){
   echo $val->getName() .' = '. $val .'<br />';
}
?
i have a file, not a string... And in this way i get all the key and string tag... But i need only the string after the key "CFBundleDisplayName" ( ASPHALT in this case )

Re: Acces XML data

Posted: Sat Mar 20, 2010 12:46 pm
by John Cartwright
iLdn wrote:
John Cartwright wrote:

Code: Select all

$xmlRoot = simplexml_load_string($your_xml_string);
 
foreach($xmlRoot->dict as $val){
   echo $val->getName() .' = '. $val .'<br />';
}
?
i have a file, not a string... And in this way i get all the key and string tag... But i need only the string after the key "CFBundleDisplayName" ( ASPHALT in this case )
1) Then use simplexml_load_file() instead

2) As you iterate the loop, check to see if the key was found yet, if not discard the current iteration (continue).