February 23, 2002 - Node Splitting by Entity References
February 23, 2002 Node Splitting by Entity References Tips: February 2002
Yehuda Shiran, Ph.D.
|
DOMDocument
tree builder splits this string in order to isolate the entity reference. The entity reference must occupy a child node by itself. So there needs to be a string portion before the entity, and a string portion following it. If the entity reference is at the beginning of the string or at its end, only two children will be created.
Here is the author
record from our mydvd example:
<author>author: &preparedby;</author>
We find the author
objects in the DOMDocument
tree as follows:
objNodeList = xmlDoc.getElementsByTagName("author");
Our author
is the first and only instance, so its index is 0
. The following script prints the text values of author
's two children, and the entity definition (2nd child's child):
alert(objNodeList(0).childNodes(0).text);
alert(objNodeList(0).childNodes(1).text);
alert(objNodeList(0).childNodes(1).childNodes(0).text);
When running this script in Internet Explorer, you should get three stings. The string before the entity reference is "author: "
, the entity reference (after substitution) is "John Smith"
, and the original entity definition is also "John Smith"
.