Hi Christophe,
Could you please let me know how did you get your XInclude working? I have not been able to get mine working.
 
I am running my application using:
$ java -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.
parsers.XIncludeParserConfiguration application_class
 
The parent.xml is :
<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href=""/'>file:///H:/ProjectAutomation/Release-1.0-Sept-3-2003/PreReq-Jars/xerces-2_5_0/child.xml"/>
</document>
where child.xml is:
<?xml version="1.0"?>
<child>
  <test>hi</test>
  <test>hello</test>
</child>
 
But the DOMParser does not iterate through the child nodes. The last node that gets printed is xi:include.
Am I supposed to make any other configuration setting?
 
Thank you.
Prapti
 
 

-----Original Message-----
From: Christophe Grosjean [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 07, 2003 5:18 AM
To: [EMAIL PROTECTED]
Subject: XInclude... is it the way to make it working ?

Hi,

 

I tried the XInclude feature. I had no problem in setting the XIncludeConfiguration and the parsing includes well

relative and absolute URI.

 

But…

 

I want to specify files in may classpath instead of URI like :

 

<xi:include href="">

 

instead of

 

<xi:include href="">

 

Setting an EntityResolver on the parser does’nt seem to work. The parser never asks the EntityResolver

to do its job.

 

Here follows the code of the EntityResolverWrapper that wraps the user-defined EntityResolver in Xerces code.

It seems that the pubId and sysId are always null, so the EntityResolver job is skipped. In my case, it is

The XMLResourceIdentifier. getLiteralSystemId() that contains the href String.

 

Is it a bug in the EntityResolverWrapper ? Do I sth wrong ?

 

I found a workaround by extending the XIncludeParserConfiguration and setting an custom XMLEntityResolver.

 

Christophe.

 

 

public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)

        throws XNIException, IOException {

 

        // When both pubId and sysId are null, the user's entity resolver

        // can do nothing about it. We'd better not bother calling it.

        // This happens when the resourceIdentifier is a GrammarDescription,

        // which describes a schema grammar of some namespace, but without

        // any schema location hint. -Sg

        String pubId = resourceIdentifier.getPublicId();

        String sysId = resourceIdentifier.getExpandedSystemId();

        if (pubId == null && sysId == null)

            return null;

 

        // resolve entity using SAX entity resolver

        if (fEntityResolver != null && resourceIdentifier != null) {

            try {

                InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);

                if (inputSource != null) {

                    String publicId = inputSource.getPublicId();

                    String systemId = inputSource.getSystemId();

                    String baseSystemId = resourceIdentifier.getBaseSystemId();

                    InputStream byteStream = inputSource.getByteStream();

                    Reader charStream = inputSource.getCharacterStream();

                    String encoding = inputSource.getEncoding();

                    XMLInputSource xmlInputSource =

                        new XMLInputSource(publicId, systemId, baseSystemId);

                    xmlInputSource.setByteStream(byteStream);

                    xmlInputSource.setCharacterStream(charStream);

                    xmlInputSource.setEncoding(encoding);

                    return xmlInputSource;

                }

            }

 

            // error resolving entity

            catch (SAXException e) {

                Exception ex = e.getException();

                if (ex == null) {

                    ex = e;

                }

                throw new XNIException(ex);

            }

        }

 

        // unable to resolve entity

        return null;

 

    }

Reply via email to