DOMParser().parseFromString() unexpectedly removes nodes from XML

909 views Asked by At

Given this XML document where xmlns:xlink="http://www.w3.org/1999/xlink" is missing:

<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book title="Harry Potter">
  <description
  xlink:type="simple"
  xlink:href="/images/HPotter.gif"
  xlink:show="new">
  As his fifth year at Hogwarts School of Witchcraft and
  Wizardry approaches, 15-year-old Harry Potter is.......
  </description>
</book>

<book title="XQuery Kick Start">
  <description
  xlink:type="simple"
  xlink:href="/images/XQuery.gif"
  xlink:show="new">
  XQuery Kick Start delivers a concise introduction
  to the XQuery standard.......
  </description>
</book>
<text>Why Am I Removed?</text>
</bookstore>

And the following javascript snippet:

var xml = '<?xml version="1.0" encoding="UTF-8"?> <bookstore> <book title="Harry Potter"> <description xlink:type="simple" xlink:href="/images/HPotter.gif" xlink:show="new"> As his fifth year at Hogwarts School of Witchcraft and Wizardry approaches, 15-year-old Harry Potter is....... </description> </book> <book title="XQuery Kick Start"> <description xlink:type="simple" xlink:href="/images/XQuery.gif" xlink:show="new"> XQuery Kick Start delivers a concise introduction to the XQuery standard....... </description> </book><text>Why Am I Removed?</text></bookstore>'
var dom = new DOMParser().parseFromString(xml, 'text/xml'); 
xml = new XMLSerializer().serializeToString(dom);

Firefox(v33.1) gives me the following error, which I expect:

prefix not bound to a namespace

And Google Chrome (v38.0.2125.111) removes the nodes with the unresolved xmlns:xlink and all nodes following (without any error):

<?xml version="1.0" encoding="UTF-8"?><bookstore> <book title="Harry Potter"> </book></bookstore>

Is there any way to get the same behaviour in Google Chrome as in Firefox ? I'm expecting a parsing error...

0

There are 0 answers