doowb / grunt-convert

Grunt task to convert to or from JSON, YAML, XML, PLIST or CSV.
MIT License
84 stars 17 forks source link

xml2json not working when the xml has any other extension #26

Closed therazor closed 10 years ago

therazor commented 10 years ago

Example:

grunt.initConfig({
  convert: {
    options: {
      explicitArray: false,
    },
    xml2json: {
      src: test/fixtures/xml2json.XYZ,
      dest: 'tmp/result/xml2json.json'
    }
  }
});

Changing the extension of the file works as intended.

doowb commented 10 years ago

We look at the file extension to determine what we need to convert from.

jonschlinkert commented 10 years ago

We look at the file extension to determine what we need to convert from.

@erethnor since you used XYZ in your example, was there a real use case that you had a problem with, or was this just experimental? If it's a real use case, can you share more information on what kind of file and extension the plugin should be recognizing?

therazor commented 10 years ago

@jonschlinkert I have an actual use case: .xmp files. Apart from the extension, they are just XML.

I could suggest 2 solutions:

or

I'd prefer solution 1 personally, as it'd be the least likely to break anything. What do you think?

aholla commented 10 years ago

I too found this. I would like to convert ".fnt" files which are actually xml files. Thanks.

jonschlinkert commented 10 years ago

thanks @hariadi!

aholla commented 10 years ago

I just gave this a go and it seems to be working but if is only converting the first file. All the other files are renamed but not actually converted:

convert: {
        options: {
          explicitArray: false,
          type: 'xml'
        },
        xml2json: {
            files: [
              {
                expand: true,
                cwd:    '<%= deployPath %>/assets/',
                src:    [ '**/*.xml', '**/*.fnt', '**/*.pex' ],
                dest:   '<%= deployPath %>/assets/',
                ext:    '.json'
              }
            ]
        },
    },

I currently have three ".fnt" files. All are duplicated and named ".json" but only the first file has actually been converted into json.

Am I doing something wrong?