Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find element when source document contain an xsd #1

Open
matthew-b-payne opened this issue Sep 3, 2014 · 3 comments
Open

Can't find element when source document contain an xsd #1

matthew-b-payne opened this issue Sep 3, 2014 · 3 comments

Comments

@matthew-b-payne
Copy link

Take document:

this is name

gulp.task('xmlmod', function() {
gulp.src("./text.xml")
.pipe(xeditor([
{path: '//name', text: 'new names2'},
{path: '//version', attr: {'major': '2'}}
]))
.pipe(gulp.dest("./dest"));
});

Works !!!

Change document to:

this is name

The task then errors with:

Error in plugin 'gulp-xml-editor'
Can't find element at "//widget"
at D:\exp\ionic-cordova-seed\node_modules\gulp-xml-editor\index.js:20:26
at Array.forEach (native)
at editByObject (D:\exp\ionic-cordova-seed\node_modules\gulp-xml-editor\index.js:17:12)
at Transform._transform (D:\exp\ionic-cordova-seed\node_modules\gulp-xml-editor\index.js:64:34)
at Transform._read (D:\exp\ionic-cordova-seed\node_modules\gulp-xml-editor\node_modules\through2\node_modules\readable-stream\lib_stream_transform.js:184:10)
at Transform._write (D:\exp\ionic-cordova-seed\node_modules\gulp-xml-editor\node_modules\through2\node_modules\readable-stream\lib_stream_transform.js:172:12)
at doWrite (D:\exp\ionic-cordova-seed\node_modules\gulp-xml-editor\node_modules\through2\node_modules\readable-stream\lib_stream_writable.js:237:10)
at writeOrBuffer (D:\exp\ionic-cordova-seed\node_modules\gulp-xml-editor\node_modules\through2\node_modules\readable-stream\lib_stream_writable.js:227:5)

@cmackay
Copy link

cmackay commented Dec 10, 2014

I had the same issue. After troubleshooting for a while, I found the following approach to work using a function as an argument and explicitly changing the root element.

var gulp = require('gulp'),
  fs = require('fs'),
  xeditor = require('gulp-xml-editor');

gulp.task('xeditor', function () {
  // using fs to prevent caching
  var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
  return gulp.src('./config.xml')
    .pipe(xeditor(function(xml, xmljs) {
      xml.root().attr({
        version: pkg.version
      });
      return xml.toString();
    }))
    .pipe(gulp.dest('./'));
});

@morou
Copy link
Owner

morou commented Dec 26, 2014

I can't understand this problem. I think @matthew-b-payne takes same document like following.

<?xml version="1.0" encoding="UTF-8"?>

this is name

What is problem? Please give me more detailed situation.

@wendellpalazzo
Copy link

wendellpalazzo commented May 23, 2016

Hi.. i have problem usign config.xml in ionicframework project..

this is the original:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="app.testing" version="0.0.21" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>myAppName</name>

using this the gulp script failed with this errors:
events.js:141
throw er; // Unhandled 'error' event
^
Error: Can't find element at "//name"

without the attributes : xmlns e xmlns:cdv.... works Fine!
<widget id="app.testing" version="0.0.21">

Can you help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants