OLD | NEW |
1 description('Test of normalize on an XML document with CDATA.'); | 1 description('Test of normalize on an XML document with CDATA.'); |
2 | 2 |
3 var parser = new DOMParser(); | 3 var parser = new DOMParser(); |
4 var serializer = new XMLSerializer(); | 4 var serializer = new XMLSerializer(); |
5 | 5 |
6 var xmlChunk = parser.parseFromString( | 6 var xmlChunk = parser.parseFromString( |
7 '<foo>' + | 7 '<foo>' + |
8 'This is some text before the CDATA' + | 8 'This is some text before the CDATA' + |
9 '<![CDATA[This is some <bold>markup</bold> inside of a CDATA]]>' + | 9 // The parser converts CDATA to Text, so the script converts this comment to
CDATA. |
| 10 '<!--This is some <bold>markup</bold> inside of a CDATA-->' + |
10 'This is some text after the CDATA' + | 11 'This is some text after the CDATA' + |
11 '</foo>', | 12 '</foo>', |
12 'application/xml'); | 13 'application/xml'); |
13 | 14 |
| 15 var comment = xmlChunk.documentElement.childNodes[1]; |
| 16 var cdata = document.implementation.createDocument(null, null).createCDATASectio
n(comment.data); |
| 17 xmlChunk.documentElement.replaceChild(cdata, comment); |
| 18 |
14 debug('Before normalize'); | 19 debug('Before normalize'); |
15 shouldBe('serializer.serializeToString(xmlChunk)', '"<foo>This is some text befo
re the CDATA<![CDATA[This is some <bold>markup</bold> inside of a CDATA]]>This i
s some text after the CDATA</foo>"'); | 20 shouldBe('serializer.serializeToString(xmlChunk)', '"<foo>This is some text befo
re the CDATA<![CDATA[This is some <bold>markup</bold> inside of a CDATA]]>This i
s some text after the CDATA</foo>"'); |
16 shouldBe('xmlChunk.documentElement.childNodes.length', '3'); | 21 shouldBe('xmlChunk.documentElement.childNodes.length', '3'); |
17 xmlChunk.documentElement.normalize(); | 22 xmlChunk.documentElement.normalize(); |
18 debug('After normalize'); | 23 debug('After normalize'); |
19 shouldBe('serializer.serializeToString(xmlChunk)', '"<foo>This is some text befo
re the CDATA<![CDATA[This is some <bold>markup</bold> inside of a CDATA]]>This i
s some text after the CDATA</foo>"'); | 24 shouldBe('serializer.serializeToString(xmlChunk)', '"<foo>This is some text befo
re the CDATA<![CDATA[This is some <bold>markup</bold> inside of a CDATA]]>This i
s some text after the CDATA</foo>"'); |
20 shouldBe('xmlChunk.documentElement.childNodes.length', '3'); | 25 shouldBe('xmlChunk.documentElement.childNodes.length', '3'); |
OLD | NEW |