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 Olivier Rossel <ol...@gmail.com> on 2008/09/26 16:07:29 UTC
XInclude with unorthodox tags.
I have some files that contain such structures:
--- before.xml ---
| ...
| <xlink:locator xlink:href="foobar.xml" xlink:type="locator"
xlink:label="foobar"/>
| ...
--- end of before.xml ---
I wish I could XInclude the foobar.xml at that precise location.
So I use a sed script that search/replace each xlink and replace it
with its xinclude counterpart.
Here is the kind of result:
--- after.xml ---
| ...
| <xinclude:include href="foobar.xml"/>
| ...
--- end of after.xml ---
And then, I use such a code to magically manages the XInclude of files:
--- myCode.java ---
| SAXParserFactory factory = (SAXParserFactory)
| SAXParserFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl",
this.getClass().getClassLoader());
| factory.setXIncludeAware(true);
| factory.setNamespaceAware(true);
| SAXParser parser = factory.newSAXParser();
| XMLReader xmlReader = parser.getXMLReader();
| sr = new org.dom4j.io.SAXReader(xmlReader);
| ...
--- end of myCode.java ---
It works perfectly fine.
But now I want to get rid of the sed script, and add some kind of
magic to manage the Xlink->XInclude in Java.
Obviously, this preprocessing must occur before the XInclude
processing of Xerces.
So I cannot use the usual XMLFilter technique (as I understand it, any
XMLFilter would occur *after* the XInclude resolving).
What is the most elegant manner to achieve my preprocessing and then
benefit from the built-in XInclude engine?
My idea was a kind of SAX pipelining, but I cannot see how to do that.
Any help is welcome.
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: XInclude with unorthodox tags.
Posted by ke...@us.ibm.com.
> XInclude support in Xerces is only available as a parsing feature.
> If there is some processing you need to do prior to XInclude you
> need to serialize the document (after you've done your
> preprocessing) and then feed it back to the parser.
Alternatively, do the processing and then implement your own include logic
-- either manually, or as an XSLT stylesheet executed with Xalan.
Re: XInclude with unorthodox tags.
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Olivier,
XInclude support in Xerces is only available as a parsing feature. If there
is some processing you need to do prior to XInclude you need to serialize
the document (after you've done your preprocessing) and then feed it back
to the parser.
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
"Olivier Rossel" <ol...@gmail.com> wrote on 09/26/2008 10:07:29
AM:
> I have some files that contain such structures:
>
> --- before.xml ---
> | ...
> | <xlink:locator xlink:href="foobar.xml" xlink:type="locator"
> xlink:label="foobar"/>
> | ...
> --- end of before.xml ---
>
> I wish I could XInclude the foobar.xml at that precise location.
>
> So I use a sed script that search/replace each xlink and replace it
> with its xinclude counterpart.
> Here is the kind of result:
>
> --- after.xml ---
> | ...
> | <xinclude:include href="foobar.xml"/>
> | ...
> --- end of after.xml ---
>
> And then, I use such a code to magically manages the XInclude of files:
> --- myCode.java ---
> | SAXParserFactory factory = (SAXParserFactory)
> | SAXParserFactory.newInstance("com.sun.org.apache.xerces.internal.
> jaxp.SAXParserFactoryImpl",
> this.getClass().getClassLoader());
> | factory.setXIncludeAware(true);
> | factory.setNamespaceAware(true);
> | SAXParser parser = factory.newSAXParser();
> | XMLReader xmlReader = parser.getXMLReader();
> | sr = new org.dom4j.io.SAXReader(xmlReader);
> | ...
> --- end of myCode.java ---
>
> It works perfectly fine.
>
>
>
> But now I want to get rid of the sed script, and add some kind of
> magic to manage the Xlink->XInclude in Java.
> Obviously, this preprocessing must occur before the XInclude
> processing of Xerces.
> So I cannot use the usual XMLFilter technique (as I understand it, any
> XMLFilter would occur *after* the XInclude resolving).
>
> What is the most elegant manner to achieve my preprocessing and then
> benefit from the built-in XInclude engine?
> My idea was a kind of SAX pipelining, but I cannot see how to do that.
>
> Any help is welcome.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org