获取cordova的config.xml的XPath

时间:2021-02-09 07:26:37

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

使用cordovas confix.xml,默认文件是这个。

<?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 of name, but no matter how I try, I can't get the right xpath to the element.

使用gulp-xml-editor我正在尝试创建一个插件来编辑name的值,但无论我如何尝试,我都无法获得正确的xpath元素。

Options I've tried:

我试过的选项:

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

To no success. Any idea what it is?

没有成功。知道它是什么?

1 个解决方案

#1


5  

The element <name> is in default namespace xmlns="http://www.w3.org/ns/widgets". Generally in xpath, to select element in namespace you'd need to register a prefix that points to the namespace uri and use that prefix in the xpath.

元素 在默认名称空间xmlns =“http://www.w3.org/ns/widgets”中。通常在xpath中,要选择命名空间中的元素,您需要注册指向命名空间uri的前缀,并在xpath中使用该前缀。

I don't know about gulp-xml-editor, but there seems a very close example in the GitHub page you linked, specifically the one commented "edit XML document by using user specific object using a namespace" :

我不知道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"));

#1


5  

The element <name> is in default namespace xmlns="http://www.w3.org/ns/widgets". Generally in xpath, to select element in namespace you'd need to register a prefix that points to the namespace uri and use that prefix in the xpath.

元素 在默认名称空间xmlns =“http://www.w3.org/ns/widgets”中。通常在xpath中,要选择命名空间中的元素,您需要注册指向命名空间uri的前缀,并在xpath中使用该前缀。

I don't know about gulp-xml-editor, but there seems a very close example in the GitHub page you linked, specifically the one commented "edit XML document by using user specific object using a namespace" :

我不知道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"));