Xpath to select sibling attribute value with namespace

I am struggling to get XPath to return a value uniqueappversionidfrom the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<manifest package="air.com.vzw.Foo" 
          android:versionCode="0" 
          android:versionName="0.0.0" 
          android:installLocation="auto"
          xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:label="FooAIR">
        <meta-data android:name="autoOrients" android:value="true" />
        <meta-data android:name="fullScreen" android:value="false" />
        <meta-data android:name="uniqueappversionid" 
                   android:value="b1e1bfa8-20b4-4724-a9c3-34b79bc50b8d" />
        <meta-data android:name="initialcontent" android:value="FooAIR.swf" />
    </application>
</manifest>

In particular, I need to get the attribute value android:valuefrom an element meta-datawith android:nameequal uniqueappversionid.

+5
source share
3 answers

With the prefix aassociated with the namespace http://schemas.android.com/apk/res/android:

/manifest
   /application
      /meta-data[@a:name='uniqueappversionid']
         /@a:value
+3
source

Well, maybe a better approach, but this is what I ended up using:

//meta-data[@*='uniqueappversionid']/@*[2]

I am very grateful for suggestions to improve this!

+2
source

, , XPath, XPath. , XSLT:

<stylesheet version="1.0"
            xmlns="http://www.w3.org/1999/XSL/Transform"
            xmlns:android="http://schemas.android.com/apk/res/android">
  <template match="/">
    <value-of select="//meta-data[@android:name = 'uniqueappversionid']/@android:value" />
  </template>
</stylesheet>

xmlns XSLT, XPath. , , () XML, . , XML.

0

All Articles