Acces XML data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
iLdn
Forum Newbie
Posts: 16
Joined: Sun Mar 14, 2010 5:04 pm

Acces XML data

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Acces XML data

Post by John Cartwright »

Code: Select all

$xmlRoot = simplexml_load_string($your_xml_string);
 
foreach($xmlRoot->dict as $val){
   echo $val->getName() .' = '. $val .'<br />';
}
?
iLdn
Forum Newbie
Posts: 16
Joined: Sun Mar 14, 2010 5:04 pm

Re: Acces XML data

Post 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 )
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Acces XML data

Post 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).
Post Reply