spacer
Yehuda Shiran February 23, 2002
Node Splitting by Entity References
Tips: February 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

In Internet Explorer, whenever there is an entity reference within an XML element's string, the 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".


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint