-
Notifications
You must be signed in to change notification settings - Fork 264
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
Serialize fails to account for text node updates #33
Comments
Ooops... forgot about preview markdown parsing... zapped my XML string in the parseFromString() command... was a simple 'sample' root with an 'el' element set to 'dummy'. |
yes it's a bug, and we can not fixed it for a long time, because of the ie6/7/8 can not support javascript getter and setter. |
Thanks.
|
@jindw I don't really know exactly what's the point being discussed here, but perhaps this article may be of help. http://johndyer.name/native-browser-get-set-properties-in-javascript/ |
|
Instead of: node.nodeValue = "New value"; I did the following: var parentNode = node.parentNode;
parentNode.removeChild(node);
var newElm = doc.createTextNode("New value");
parentNode.appendChild(newElm); And it works fine! |
The root of this issue seems to be that when using |
Assuming D is a parsed-in XML DOM.
Assume further some text nodes in D are modified using
D.getElementsByTagName(...)[0].childNodes[0].nodeValue = ...;
Serializing D produces the original (unmodified parsed-in DOM)!
However, explicit reference to the modified nodes produces the expected (modified) values!
Issue demo code...
var winston = require('winston'); //multi-transport logger
var logger = new (winston.Logger) ({
transports: [
new winston.transports.Console({colorize: true})
]
});
var DOMParser = require('xmldom').DOMParser;
var XMLSerializer = require('xmldom').XMLSerializer;
var D = new DOMParser().parseFromString('dummy');
logger.info('Original element value= ' + D.getElementsByTagName('el')[0].childNodes[0].nodeValue);
D.getElementsByTagName('el')[0].childNodes[0].nodeValue = 'updated';
logger.info('Updated element value= ' + D.getElementsByTagName('el')[0].childNodes[0].nodeValue);
logger.info('Serialized updated D = ' + new XMLSerializer().serializeToString(D));
The text was updated successfully, but these errors were encountered: