Getting XPath for Cordova config.xml

With cordovas confix.xml, this is the default file.

<?xml version='1.0' encoding='utf-8' ?>
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>HelloCordova</name>
  <description>
    A sample Apache Cordova application that responds to the deviceready event.
  </description>
  <author email="dev@cordova.apache.org" href="http://cordova.io">
    Apache Cordova Team
  </author>
  <content src="index.html" />
  <plugin name="cordova-plugin-whitelist" version="1" />
  <access origin="*" />
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
  <allow-intent href="sms:*" />
  <allow-intent href="mailto:*" />
  <allow-intent href="geo:*" />
  <platform name="android">
    <allow-intent href="market:*" />
  </platform>
  <platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
  </platform>
</widget>

Using gulp-xml-editor I'm trying to create a plugin to edit the value name, but no matter how hard I try, I cannot get the correct xpath for the element.

Parameters I tried:

  • .//*[name]
  • .//*/widgets:name
  • //name

Without success. Any idea what this is?

+4
source share
1 answer

The item <name>is in the default namespace xmlns="http://www.w3.org/ns/widgets". Typically, in xpath, to select an item in the namespace, you need to register a prefix pointing to the namespace uri and use this prefix in xpath.

gulp-xml-editor, GitHub , , " XML- ":

/*
  edit XML document by using user specific object using a namespace
*/
gulp.src("./manifest.xml")
  .pipe(xeditor([
    {path: '//xmlns:name', text: 'new names'},
  ], 'http://www.w3.org/ns/widgets'))
  .pipe(gulp.dest("./dest"));
+5

Source: https://habr.com/ru/post/1589313/


All Articles