spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column103


Web Services, Part VIII: Reading DTDs with JavaScript

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


Adding Entity References on the Fly

You can create entity references on the fly. Remember our date element from mydvd7.xml:

<date>Jan 30, 2002</date>

Let's add an entity reference for the day of the week, before the date. We have already prepared the substitution in the DTD file:

<!ENTITY day "Wednesday, ">

First, let's create the entity reference node:

var newEntityReference = xmlDoc.createEntityReference("day");

Find the first and only date element:

objNodeList = xmlDoc.getElementsByTagName("date");

Now, insert the new node as a child of the date element, before its first child, the text: Jan 30, 2002:


objNodeList(0).insertBefore(newEntityReference,
  objNodeList(0).childNodes(0));

Let's verify now that the date element has two children: "Wednesday, " and "Jan 30, 2002". The following lines print these two nodes, as well as the child of the entity reference:

alert(objNodeList(0).childNodes(0).text);
alert(objNodeList(0).childNodes(1).text);
alert(objNodeList(0).childNodes(0).childNodes(0).text);

Running this script will yield the two expected results. But notice that the entity reference has its own child which is also "Wednesday, ".


Next: code listings

http://www.internet.com

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


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: February 11, 2002
Revised: February 11, 2002

URL: http://www.webreference.com/js/column103/7.html