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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business