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

Serialize fails to account for text node updates #33

Open
braytak opened this issue Aug 21, 2012 · 7 comments
Open

Serialize fails to account for text node updates #33

braytak opened this issue Aug 21, 2012 · 7 comments

Comments

@braytak
Copy link

braytak commented Aug 21, 2012

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));

@braytak
Copy link
Author

braytak commented Aug 21, 2012

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'.

@jindw
Copy link
Owner

jindw commented Oct 2, 2012

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.

@braytak
Copy link
Author

braytak commented Oct 2, 2012

Thanks.
I work around it the long way... using 'replaceChild'
--pier
On 02/10/12 09:42, jindw wrote:

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.


Reply to this email directly or view it on GitHub
#33 (comment).

@arboleya
Copy link

@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/

@DullReferenceException
Copy link

replaceChild isn't working either for replacing the text node; it's still serialized with the original value. Neither does changing textContent.

@fruityfred
Copy link

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!

@cburatto
Copy link

cburatto commented Jul 11, 2019

The root of this issue seems to be that when using nodeValue = the data property is not updated simultaneously. Check my comment here #116 (comment)

emmkimme pushed a commit to emmkimme/xmldom that referenced this issue Jul 8, 2020
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

6 participants