<$BlogRSDUrl$> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } }
Friday, May 14, 2004

XML Parsing Tips 

* If you parse the document in the constructor, keep a method to return the
parsed doc. In case of explicit parse methods also, it is a good idea to
have
a method returning doc.

* Some of the properties of DOM Parser can be set using the setFeature()
method.

* Incase we are extending the parser to get functionality specific to our
problem, it makes sense to graft a method , which can be named print(),
which
does the printing specific to our problem. Usually this method is a giant
switch case, with
customized processing for each tag.

* If we are writing our own parsers, we may be required to provide
customized
* processing of methods in XMLDocumentHandler interface.

Some imp methods are :-
a) startDocument()
b) startElement()
c) comment()
d) characters()


* If you want to maintain some data per node, use the setUserData() method
of
Node interface. Typically this is used in conjunction with getProperty()
method of Node.

* Line Numbers are maintained using XMLErrorReporter's getLocator() method
which returns a Locator.

NOTE: Locator possibly has a bug while returning the line number for the
first(document?) node.

* We parse first and then we traverse the DOM to grab tokens of interest.

This page is powered by Blogger. Isn't yours?