One might assume from the previous example that the title of the album, "Disco <XML>" can be added in the same way as the name of the artist. However, a quick glance at the text of the proposed node shows a problem with this approach:
<title>Disco <XML></title>
The angle brackets in the title are indistinguishable from standard XML angle brackets! Although this will not cause a problem when creating a node, an XML parser would trip up on any string that did not notify it in some way that "<XML>" was textual data, not an XML Element!
The DOM specification provides a way around this issue - the CDATASection node. An XML parser will interpret anything within a CDATASection node as textual data. It looks like this:
<title><![CDATA[Disco <XML>]]</title>
A DOMIT_CDATASection node is created like this:
$titleNode =& $cdCollection->createCDATASection("Disco <XML>");
And we can add the new title node in the usual way:
$newCDNode ->childNodes[1]->appendChild($titleNode);
Note that you cannot nest CDATASection nodes.
|