XNI - inserting an element/string/?? 2003-08-18 - By Elena Litani
Hi Robert,
You need to add a new filter component to your parser pipeline. Your filter must implement xni.parser.XMLDocumentFilter interface, and should be responsible for adding a new element by calling an extra startElement method.
You need also create your own configuration that will include this new filter component. Just extend one of the existing configurations, i.e. org.apache.xerces.parsers.DTDConfiguration or IntegratedParserConfiguration (if you are worried about XML Schema validation) and overwrite configurePipeline() method. For example, if you want your filter to be the last component in the pipeline your code for configurePipeline() should look as follows:
super.configurePipeline(); fLastComponent.setDocumentHandler(fMyFilter); if (fDocumentHandler != null) { fDocumentHandler.setDocumentSource(fMyFilter); } fLastComponent = fMyFilter;
Then, create a parser, i.e. org.apache.xerces.parsers.DOMParser, passing in the constructor this new configuration you want to use.
Read more about XNI pipelines here: http://xml.apache.org/xerces2-j/xni-config.html
Also you can look at existing filter components and their implementation: org.apache.xerces.impl.XMLNamespaceBinder, org.apache.xerces.impl.dtd.XMLDTDValidator, etc.
Hope it helps, -- Elena Litani / IBM Toronto
Robert Koberg wrote: > > Hi, > > I have XML that looks like: > > <list> > <item/> > <item/> > </list> > > I want to use XNI to insert an 'item element' when the 'endElement' event is > triggered for the closing 'list element.' > > So far, I have tried extending the XNIPassThroughFilter. I would think that > I could call a super.startElement passing it the appropriate objects. But > since it is not readily available, I was wondering if there was a different > way. Should I just an insert a character buffer (or something similar) into > the XmlInputSource? If so, how? > > Is there a simple way to add an element during a XNI parse/filter? > > Thanks for any hints or pointers, > -Rob > > --------------------------------------------------------------------- > To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) > For additional commands, e-mail: xerces-j-user-help@(protected)
-- Elena Litani / IBM Toronto
--------------------------------------------------------------------- To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|