Created
March 10, 2013 03:17
-
-
Save tungd/5126965 to your computer and use it in GitHub Desktop.
Sample XML processing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.stockrobot" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-sdk android:minSdkVersion="8" /> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
<application android:icon="@drawable/ic_launcher" android:label="Stock Robot"> | |
<activity | |
android:name=".LogInActivity"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
<!-- Menu Screen --> | |
<activity | |
android:name=".MenuActivity" | |
android:theme="@android:style/Theme.Light.NoTitleBar" > | |
</activity> | |
<!-- Market Screen --> | |
<activity | |
android:name=".MarketActivity" | |
android:theme="@android:style/Theme.Black.NoTitleBar" > | |
</activity> | |
<!-- Register Screen --> | |
<activity | |
android:name=".RegisterActivity" | |
android:theme="@android:style/Theme.Light.NoTitleBar" > | |
</activity> | |
<!-- TabLayout Screen --> | |
<activity | |
android:name=".TabLayoutActivity" | |
android:theme="@android:style/Theme.NoTitleBar" > | |
</activity> | |
<!-- Own list Screen --> | |
<activity android:name=".OwnListActivity" > | |
</activity> | |
<!-- All list Screen --> | |
<activity android:name=".AllListActivity" > | |
</activity> | |
<!-- Watch list Screen --> | |
<activity android:name=".WatchListActivity" > | |
</activity> | |
<!-- Follow list Screen --> | |
<activity android:name=".FollowListActivity" > | |
</activity> | |
<!-- Month list Screen --> | |
<activity | |
android:name=".FollowListActivity" | |
android:theme="@android:style/Theme.NoTitleBar" > | |
</activity> | |
<!-- Year list Screen --> | |
<activity | |
android:name=".YearListActivity" | |
android:theme="@android:style/Theme.NoTitleBar" > | |
</activity> | |
<!-- Detail Activity --> | |
<activity | |
android:name=".DetailActivity" | |
android:theme="@android:style/Theme.NoTitleBar" > | |
</activity> | |
<!-- Company Detail Activity --> | |
<activity | |
android:name=".CompanyDetailActivity" | |
android:theme="@android:style/Theme.NoTitleBar" > | |
</activity> | |
<!-- Search Activity --> | |
<activity | |
android:name=".SearchActivity" | |
android:theme="@android:style/Theme.NoTitleBar" > | |
</activity> | |
<!-- User Activity --> | |
<activity | |
android:name=".UserActivity" | |
android:theme="@android:style/Theme.NoTitleBar" > | |
</activity> | |
<!-- History Activity --> | |
<activity | |
android:name=".HistoryActivity" | |
android:theme="@android:style/Theme.NoTitleBar" > | |
</activity> | |
</application> | |
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import javax.xml.xpath.*; | |
import org.xml.sax.InputSource; | |
import org.w3c.dom.NodeList; | |
import org.w3c.dom.Node; | |
public class ManifestParser { | |
public static void main(String args[]) { | |
try { | |
InputStream source = new FileInputStream("AndroidManifest.xml"); | |
try { | |
XPathFactory xPathfactory = XPathFactory.newInstance(); | |
XPath xpath = xPathfactory.newXPath(); | |
XPathExpression expr = xpath.compile("/manifest/application/activity"); | |
NodeList nodes = | |
(NodeList) expr.evaluate(new InputSource(source), XPathConstants.NODESET); | |
System.out.printf("Found %d activities\n", nodes.getLength()); | |
for (int i = 0, len = nodes.getLength(); i < len; i += 1) { | |
System.out.printf(" %s\n", | |
nodes.item(i).getAttributes().getNamedItem("android:name").getNodeValue()); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment