You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Robert Koberg <ro...@koberg.com> on 2003/08/18 22:08:47 UTC
XNI - inserting an element/string/??
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@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
RE: XNI - inserting an element/string/??
Posted by Robert Koberg <ro...@koberg.com>.
Hi,
I was tryng to use JARV to do validation after the XNI include and parse. If
valid then write, else send error, etc...
AddContentMetadataHandler (constructed below) in a XNI handler and in it I
have:
public void endElement(QName element, Augmentations augs) throws
XNIException
{
// How to insert element w/attrs, bytes, chars string, etc???
// It would be nice to be able to do:
//if (target) {
// super.startElement(name, attrs, augs);
// super.endElement(name, augs);
//}
super.endElement(element, augs);
}
Thanks, Rob
---------------------------------
VerifierFactory factory = new com.sun.msv.verifier.jarv.TheFactoryImpl();
Schema schema =
factory.compileSchema(Lsb.getXsdContentConfigPath().openRead());
Verifier verifier = schema.newVerifier();
verifier.setErrorHandler(
com.sun.msv.verifier.util.ErrorHandlerImpl.theInstance );
VerifierFilter filter = verifier.getVerifierFilter();
XMLReader reader = XMLReaderFactory.createXMLReader();
filter.setParent( reader );
filter.setContentHandler(new AddContentMetadataHandler());
filter.parse(new
InputSource(project.getContentConfigPath().openRead().getReader()));
> -----Original Message-----
> From: Elena Litani [mailto:elitani@ca.ibm.com]
> Sent: Wednesday, August 20, 2003 6:48 AM
> To: xerces-j-user@xml.apache.org
>
> Robert,
>
> You don't need to use DOMParser - I was just giving it as an example.
> You can invoke parser on configuration, however you do need to register
> some document handler. In the case of DOM the document handler is
> DOMParser, in the case of SAX the document handler is SAXParser. So what
> do you register as documentHandler for XNI parse?
>
> Thank you,
> --
> Elena Litani / IBM Toronto
>
> Robert Koberg wrote:
> >
> > Hi and thanks,
> >
> > I have a filter setup. But, I was not specific, but I was hoping to do
> this
> > without using the DOM. I was hoping to run a XNI parse and then at some
> > point insert something in the source.
> >
> > Is there anyway to do this? Or can you add only with the DOM?
> >
> > Thanks,
> > -Rob
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: XNI - inserting an element/string/??
Posted by Elena Litani <el...@ca.ibm.com>.
Robert,
You don't need to use DOMParser - I was just giving it as an example.
You can invoke parser on configuration, however you do need to register
some document handler. In the case of DOM the document handler is
DOMParser, in the case of SAX the document handler is SAXParser. So what
do you register as documentHandler for XNI parse?
Thank you,
--
Elena Litani / IBM Toronto
Robert Koberg wrote:
>
> Hi and thanks,
>
> I have a filter setup. But, I was not specific, but I was hoping to do this
> without using the DOM. I was hoping to run a XNI parse and then at some
> point insert something in the source.
>
> Is there anyway to do this? Or can you add only with the DOM?
>
> Thanks,
> -Rob
>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
RE: XNI - inserting an element/string/??
Posted by Robert Koberg <ro...@koberg.com>.
Hi and thanks,
I have a filter setup. But, I was not specific, but I was hoping to do this
without using the DOM. I was hoping to run a XNI parse and then at some
point insert something in the source.
Is there anyway to do this? Or can you add only with the DOM?
Thanks,
-Rob
> -----Original Message-----
> From: Elena Litani [mailto:elitani@ca.ibm.com]
> Sent: Monday, August 18, 2003 2:36 PM
> To: xerces-j-user@xml.apache.org
>
> 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
> --
> Elena Litani / IBM Toronto
>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: XNI - inserting an element/string/??
Posted by Elena Litani <el...@ca.ibm.com>.
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@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
--
Elena Litani / IBM Toronto
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org