Tuesday, August 6, 2013

Get XML (android:versionCode="1") attributes value using PHP Functionality

// XML File Contents
<?xml version="1.0" encoding="utf-8"?><manifest android:versionCode="1" android:versionName="1.0" package="com.example.myfirstapp"  xmlns:android="http://schemas.android.com/apk/res/android">    <application android:theme="@style/AppTheme" android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:debuggable="true" android:allowBackup="true">        <activity android:label="@string/app_name" android:name="com.example.myfirstapp.MainActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>


// PHP Code for get (android:versionCode="1") versioncode,(android:versionName="1.0") Versionname and    (package) package value.It's Working only above PHP Version 5.3.8 


<?php 
$dom = new DOMDocument();$dom->load('AndroidManifest.xml');$xml = simplexml_import_dom($dom);$versionName = $xml->xpath('/manifest/@android:versionName');$versionCode =$xml->xpath('/manifest/@android:versionCode');$package = $xml->xpath('/manifest/@package');
echo $versionName[0]->versionName;echo $versionCode[0]->versionCode;echo $package[0]->package;
?>

No comments:

Post a Comment