jindw / xmldom

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

(nodeSerializeToString) TypeError: Cannot read property 'prefix' of null #228

Open aniltallam opened 6 years ago

aniltallam commented 6 years ago

Following code is throwing error at line number 3

let xmlString = '<?xml version="1.0" encoding="utf-8"?>'
let doc = new Dom().parseFromString(xmlString)
let nXmlString = doc.toString()

Error details:

TypeError: Cannot read property 'prefix' of null at Document.nodeSerializeToString [as toString] (E:\repos\temp\integrator-adaptor\node_modules\xmldom\dom.js:920:22)

avral commented 6 years ago

same error

ash-lionell commented 6 years ago

For me, this happens whenever I perform a delete operation using "removeChild". I want to update the dom as I process individual nodes. But this issue is preventing me from completing that solution.

darlenya commented 5 years ago

Got the same Error with:

const xmldom = require('xmldom')
const domParser = new xmldom.DOMParser()
const xmlSerializer = new xmldom.XMLSerializer()

let xmlString = '<?xml version="1.0" encoding="utf-8"?>'
let doc =  domParser.parseFromString(xmlString)
let nXmlString = xmlSerializer.serializeToString(doc)
console.log(nXmlString)

But when you change <?xml version="1.0" encoding="utf-8"?> to <?xml version="1.0" encoding="utf-8"?><div/>

it will work

amitguptagwl commented 5 years ago

This project is not active anymore. You can try fast-xml-parser instead

sntran commented 5 years ago

Possibly from #124 .