Reputation: 233
I have a simple requirement where in I need to fetch the value of attribute xml:id
i.e af1
.
I am making use of a SAXParser
and here is my xpath:a/aff/@xml:id
on the contrary I was able to fetch value of using the xpath:a/aff/@value
.
But i was unable to retrieve the value could you please help me?
<?xml version="1.0" encoding="UTF-8" ?>
<a>
<aff xml:id="af1" value="a">
<uAff>
Hello
</uAff>
</aff>
<aff xml:id="corr1">
<uAff>
Hello1
</uAff>
</aff>
</a>
Thanks in advance.
Upvotes: 17
Views: 6717
Reputation: 1167
@tibtof's solution worked for my complex Cordova config.xml transformation using gulp and gulp-xml-transformer to fix the ionic-plugin-deeplinks AndroidManifest.xml implementation by targeting the android:host
attribute like so since the colon in the attribute name would not work with path: '//xmlns:platform[@name="android"]/xmlns:config-file/xmlns:intent-filter/xmlns:data[@android:host]'
:
gulpfile.js:
var gulp = require('gulp'),
xeditor = require("gulp-xml-transformer");
function config(avc, bundleId, ioscfbv, version, appLabel, hostname, done) {
gulp.src('config.xml')
.pipe(xeditor([
{
path: '//xmlns:widget',
attr: { 'android-versionCode': avc, 'id': bundleId, 'ios-CFBundleVersion': ioscfbv, 'version': version }
},
{
path: '//xmlns:name',
text: appLabel
},
{
path: '//*[@name="Hostname"]',
attr: { 'value': bundleId }
},
{
path: '//*[@name="ios"]/xmlns:config-file/xmlns:array/xmlns:string',
text: 'applinks:' + hostname
},
{
path: '//xmlns:platform[@name="android"]/xmlns:config-file/xmlns:intent-filter/xmlns:data[@*[name()="android:host"]]',
attr: { 'android:host': hostname }
}
], 'http://www.w3.org/ns/widgets'))
.pipe(gulp.dest('.'))
.on('finish', done);
}
config.xml:
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0" android-versionCode="0" id="com.bundle.placeholder" ios-CFBundleVersion="1.0.0.0" version="1.0.0">
...
<platform name="android">
...
<config-file target="AndroidManifest.xml" parent="/manifest/application/activity">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="https"/>
<data android:host="com.bundle.placeholder"/>
</intent-filter>
</config-file>
...
</platform>
...
</widget>
Upvotes: 0
Reputation: 7967
To get the value of the attributes you could use:
/a/aff/@*[name()='xml:id']
Upvotes: 28
Reputation: 771
/a/aff/@xml:id works just fine in getting the values...
Are you trying to get both values?
If you are trying to get just the first value you could use /a/aff[1]/@xml:id
Upvotes: 1