kirbysayshi / vash

Vash, the 60 billion double-dollar template-maker. Razor syntax, for JavaScript templates
Other
522 stars 60 forks source link

Error when includes more than one XMLNS #93

Closed dandanknight closed 8 years ago

dandanknight commented 8 years ago

Hi there, I'm looking to create a pretty complicated XML, that includes about 8 namespaces. When I create a template, if I reference more than one namespace, I get the following error.....

/Users/dan/WebstormProjects/adiBuilder/node_modules/vash/lib/parser.js:108
  var consumed = this[dispatch](this.node, curr, next, ahead, nnwon);
                               ^
TypeError: undefined is not a function
    at Parser.read (/Users/dan/WebstormProjects/adiBuilder/node_modules/vash/lib/parser.js:108:32)
    at Object.exports.compile (/Users/dan/WebstormProjects/adiBuilder/node_modules/vash/index.js:62:33)
    at Object.<anonymous> (/Users/dan/WebstormProjects/adiBuilder/app.js:30:16)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

This is before I include any variables/model or anything, seems to just fails parsing.

So, this works....

var tpl = vash.compile('<?xml version="1.0" encoding="UTF-8"?><ADI xmlns:core="http://www.cablelabs.com/namespaces/metadata/xsd/core/1" xmlns:ext="URN:NNDS:CMS:ADI3:01" xmlns="http://www.cablelabs.com/namespaces/metadata/xsd/vod30/1"><ext:title><AnotherElement>Hello</AnotherElement></ext:title></ADI>');

var out = tpl({});

...and XML pretty printed...

<?xml version="1.0" encoding="UTF-8"?>
<ADI xmlns:core="http://www.cablelabs.com/namespaces/metadata/xsd/core/1" xmlns:ext="URN:NNDS:CMS:ADI3:01"
     xmlns="http://www.cablelabs.com/namespaces/metadata/xsd/vod30/1">
    <ext:title>
        <AnotherElement>Hello</AnotherElement>
    </ext:title>
</ADI>

And this does not work...

var tpl = vash.compile('<?xml version="1.0" encoding="UTF-8"?><ADI xmlns:core="http://www.cablelabs.com/namespaces/metadata/xsd/core/1" xmlns:ext="URN:NNDS:CMS:ADI3:01" xmlns="http://www.cablelabs.com/namespaces/metadata/xsd/vod30/1"><ext:title><core:AnotherElement>Hello</core:AnotherElement></ext:title></ADI>');

var out = tpl({});

...and XML pretty printed...

<?xml version="1.0" encoding="UTF-8"?>
<ADI xmlns:core="http://www.cablelabs.com/namespaces/metadata/xsd/core/1" xmlns:ext="URN:NNDS:CMS:ADI3:01"
     xmlns="http://www.cablelabs.com/namespaces/metadata/xsd/vod30/1">
    <ext:title>
        <core:AnotherElement>Hello</core:AnotherElement>
    </ext:title>
</ADI>

Maybe Vash isn't the ideal tool for creating XMLs this way, any help is appreciated.

Dan

kirbysayshi commented 8 years ago

Hello!

Vash is definitely not well prepared for XML. It's parser is well tested against html at the moment, but xml is new territory.

But I just pushed a fix (v0.11.0) that will solve the problem you were having. It was related to the colons in the namespaces: vash wasn't treating them as part of the tag name.

Hope this helps, and let me know if you run into more issues!

dandanknight commented 8 years ago

Hi kirbysayshi, wow, amazing response! Thank you so much. I'll give the new version a go right now.