0

I have a android manifest file that is xml. Suppose its data is stored in a string variable $xmldata as below: <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versioncode="13507140" android:versionname="1.35.7" package="com.google.android.apps.youtube.music" platformbuildversioncode="23" platformbuildversionname="6.0-2166767"> <uses-sdk android:minsdkversion="16" android:targetsdkversion="23"> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"> <uses-feature android:name="android.hardware.screen.portrait"> <compatible-screens> <screen android:screensize="200" android:screendensity="160"> <screen android:screensize="200" android:screendensity="240"> <screen android:screensize="200" android:screendensity="320"> <screen android:screensize="400" android:screendensity="420"> <screen android:screensize="400" android:screendensity="480"> <screen android:screensize="400" android:screendensity="560"> <screen android:screensize="400" android:screendensity="640"> </screen></screen></screen></screen></screen></screen></screen></compatible-screens> </uses-feature></uses-permission></uses-sdk></manifest>

How to get all android:screendensity values in array? This is android manifest file so xml structure differs from normal xml file. View Full XML here.

Mihir
  • 306
  • 3
  • 18
  • 2
    Possible duplicate of [How do you parse and process HTML/XML in PHP?](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – ThW Jul 24 '16 at 10:06

1 Answers1

1

I think your xml is wrong.
The "screen" tag should be closed like this:

<compatible-screens>
    <screen android:screenSize="200" android:screenDensity="160"/>
    <screen android:screenSize="200" android:screenDensity="240"/>
    <screen android:screenSize="200" android:screenDensity="320"/>
    <screen android:screenSize="400" android:screenDensity="420"/>
    <screen android:screenSize="400" android:screenDensity="480"/>
    <screen android:screenSize="400" android:screenDensity="560"/>
    <screen android:screenSize="400" android:screenDensity="640"/>
</compatible-screens>

Then if you use PHP, use parser library as commented by @ThW.
Or I recommend you to use regular expression like this:

preg_match_all("/screenDensity=\"(\d+)\"/", $xmldata, $result);

// $result[1]; is array of screenDensitys
nshmura
  • 5,940
  • 3
  • 27
  • 46