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

nodeValue of Attr #107

Open
ringel7 opened this issue Jan 8, 2015 · 0 comments
Open

nodeValue of Attr #107

ringel7 opened this issue Jan 8, 2015 · 0 comments

Comments

@ringel7
Copy link

ringel7 commented Jan 8, 2015

Hi, I wrote the followings:

var DOMParser = require("xmldom").DOMParser;
var XMLSerializer = require("xmldom").XMLSerializer;

var xml = new DOMParser().parseFromString("<x></x>", 'text/xml');
var attr = xml.createAttribute("a");
attr.nodeValue = "b";
xml.documentElement.setAttributeNode(attr);

var str = new XMLSerializer().serializeToString(xml);
console.log(str);

The result:

> node domsample.js

C:\Users\xxx\AppData\Roaming\npm\node_modules\xmldom\dom.js:952
                return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),
                                                              ^
TypeError: Cannot call method 'replace' of undefined
    at serializeToString (C:\Users\xxx\AppData\Roaming\npm\node_modules\xmldom\dom.js:952:49)
    at serializeToString (C:\Users\xxx\AppData\Roaming\npm\node_modules\xmldom\dom.js:923:4)
    at serializeToString (C:\Users\xxx\AppData\Roaming\npm\node_modules\xmldom\dom.js:947:4)
    at XMLSerializer.serializeToString (C:\Users\xxx\AppData\Roaming\npm\node_modules\xmldom\dom.js:907:2)
    at Object.<anonymous> (C:\home\xmldom\domsample.js:9:31)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

I think that nodeValue of Attr should be the alias of value property.

        Object.defineProperty(Attr.prototype,'nodeValue',{
            get:function(){
                return this.value;
            },
            set:function(data){
                this.value = data;
            }
        })

dom standard of whatwg (https://dom.spec.whatwg.org/#interface-attr) defines:

interface Attr {
  attribute DOMString value;
  attribute DOMString nodeValue; // legacy alias of .value
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

1 participant