jindw / xmldom

A PURE JS W3C Standard based(XML DOM Level2 CORE) DOMParser and XMLSerializer.
Other
819 stars 265 forks source link

Formatting changed when xml document is written back to file. #186

Closed Ajay-MS closed 8 years ago

Ajay-MS commented 8 years ago

Hello Team,

I am using xmldom module for some development, its good module for making any operation in xml. But I endup with one error. Let's earlier i had A.xml, then using xmldom i did some changes to A.xml and write back to B.xml.

My application was working fine with A.xml but it' started saying B.xml is invalid( Unexpected end of file has occurred) . On comparing A.xml and B.xml , I found then while writing serialized data of dom to xml back, new line character after metadata and comments has been removed.

Can you help me by telling best way to write xmldom back to file in formatted form. I used following method

fs.writeFile("B.xml", serializer.serializeToString(xmlDocument), function (error) {
            if (error) {
                throw new Error("unable to update");
            }
            else {
                console.log(tl.loc("Configfileupdated", configFile));
            }
        });
jindw commented 8 years ago

your means the white space between the xml processor and the document root node?

Ajay-MS commented 8 years ago

@jindw Yes format is getting changed. But problem I was facing was not because of that. But still I want to know how i can format my xml again same as my original xml file.

I found one node module https://github.com/michaelrhodes/simple-xml-dom . But since there is dependency conflicts I haven't tried it.

jindw commented 8 years ago

maybe simple-xml-dom is a fast chooice xmldom is not focus on source edit before.

xmlprocessor and attributes whitespace will ignored

Ajay-MS commented 8 years ago

@jindw Yes I too didn't felt much confident with sinple-xml-dom, meanwhile i was also able to resolve problem i was facing. I am unblocked for now, Just asking this for curiosity.

Thanks 👍

jindw commented 8 years ago

fixed! but the \n in xml attribute is ignored