Re: [xmljs-users] Whitespace stripped before/after entities.
Brought to you by:
djoham,
witchhunter
From: David J. <dj...@ya...> - 2004-03-20 07:19:00
|
Hi Stepan, I *think* I might have a fix for this. I'll give it more of a look tomorrow and if it does work, send you a new copy of xmlw3cdom.js. What *are* you doing to my poor parser anyway? :) David --- Stepan Riha <xm...@no...> wrote: > The W3CDOM parser incorrectly strips whitespace before and after entities. For > example, the tag > <TAG>Say Hello <b>World</b> and Sky</TAG> > should be parsed as > "Say Hello <b>World</b> and Sky" > but is incorrectly parsed as > "Say Hello<b>World</b>and Sky" > > A workaround (for my application) is to use > parser.preserveWhiteSpace = true; > and then trim the text nodes myself. > > The problem is caused in DOMImplementation__parseLoop() where you trim pContent > in XMLP._TEXT nodes. The trimming should really only happen after text nodes > have been normalized (and thus contain entities). > > The following demonstrates the problem: > > function xmljsDOMExample() { > var xml; > xml = "" > + "<?xml version=\"1.0\"?>" > + "<ROOT>" > + "<TAG1>" > + "Say Hello <b>World</b> and Sky" > + "</TAG1>" > + "</ROOT>"; > > //instantiate the W3C DOM Parser > var parser = new DOMImplementation(); > > parser.preserveWhiteSpace = true; > > //load the XML into the parser and get the DOMDocument > var domDoc = parser.loadXML(xml); > > //get the root node > var docRoot = domDoc.getDocumentElement(); > > //get the "TAG1" element > var tag1 = docRoot.getElementsByTagName("TAG1").item(0); > > //the following should be > //"Hello <b>World</b> and Sky" > alert(tag1.firstChild.data); > }// end function xmljsDOMExample > > - Stepan > > -- > Stepan Riha > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > xmljs-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmljs-users __________________________________ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html |