jdom parses coloned properties of xml files

Keywords: Android xml Unity SDK

jdom parses coloned properties of xml files

For reprinting, please indicate the source:
https://dujinyang.blog.csdn.net/article/details/99644824
This article is from: [Ottoman Superman's Blog]

If the xml file parsing with colon attributes, usually to deal with special, here is the namespace, N years ago encountered a forgotten record, and later forgotten, this record again.

Solved, recorded, shared to you, Baidu to all is useless, here we need to parse the attributes.

DOM4J can be used, but it is convenient for the lightweight project. After the tangle, use JDOM this time.

Previously, the normal node's xml was used, but now it's some configuration files of android, so a series of exceptions occurred later, such as: JDOM cannot handle metadata attributes with namespace prefix and so on...

Baidu Google in the middle for a while, no results, but also looked at XPath, Jaxen, XNode, XDocument and so on, why so complex can not go back, has obtained the element of the root node, think about, jdom should consider with the parsing colon, some can be replaced by @, but jdom tried for a long time, no results.

Finally, it took a long time to analyze the source code to find the problem:

Since what we need is the node attribute with colon, we definitely need to make NameSpace namespace. We don't need XPATH or jaxen, otherwise it's the default namespace.

So just specify here:

Namespace type=Namespace.getNamespace("android","http://schemas.android.com/apk/res/android");
System.out.println(ele.getAttributeValue("name",type));

XML file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
android:compileSdkVersion="29" 
android:compileSdkVersionCodename="6.2-2438415" 
android:installLocation="auto" 
package="com.dujinyang.xxxx"
platformBuildVersionCode="23" 
platformBuildVersionName="6.2-2438415">
    <uses-feature android:glEsVersion="0x000520000"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.READ_LOGS"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.GET_TASKS"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
    <application android:allowBackup="true" android:banner="@drawable/app_banner" android:debuggable="false" android:hasCode="true"  android:icon="@drawable/app_icon" android:isGame="true" android:label="immqy" android:largeHeap="true" android:name="com.dujinyang.xxxx"  android:theme="@style/UnityThemeSelector">
        <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize" android:icon="@drawable/app_icon" android:label="immqy" android:launchMode="singleTop" android:name="com.immqy.3d.activity.UnityMainActivity" android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
                <category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
            </intent-filter>
        </activity>
        <meta-data android:name="unity.build-id" android:value="abc53v45wtw5aasdfg"/>
        <meta-data android:name="unity.splash-mode" android:value="1"/>
        <meta-data android:name="unity.splash-enable" android:value="true"/>
        <meta-data android:name="android.max_aspect" android:value="3"/>
        <meta-data android:name="POOLSDK_CHANNEL_ID" android:value="5201314"/>
        <meta-data android:name="POOLSDK_CUSTOM_ID" android:value="{}"/>
        <activity android:configChanges="keyboardHidden|orientation|screenSize" android:launchMode="singleTask" android:name="com.DUJINYANG.sdk.view.WebViewActivity" android:screenOrientation="portrait"/>
        <service android:exported="true" android:name="com.ch.sys.sdk.service.FloatViewService"/>
        <activity android:configChanges="keyboardHidden|orientation|screenSize" android:name="com.KARL.sdk.H5WebViewActivity" android:screenOrientation="portrait"/>
        <meta-data android:name="SBSBSB" android:value="67329"/>
    </application>
</manifest>

Contact information please see the home page, if you have any complications, you can see here: Bug's Difficulties | No Language

|| Copyright Statement: This article is an original article by blogger Du Jinyang. Please indicate the origin of the article when it is reproduced.

Posted by Revlet on Thu, 15 Aug 2019 03:03:21 -0700