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 Mark Brucks <br...@charter.net> on 2009/09/16 18:22:41 UTC

xml include

I would like to know which elements in a document exist as a result of  
XInclude processing and I need to retrieve the original <include>  
element so that I have access to the entire set of attributes.

My only solution, which I don't like, involves parsing the document  
twice.  The first parse sets the xinclude feature of the DOMParser  
(actually, of the underlying XIncludeAwareParserConfiguration), the  
second parse has that feature turned off. The second parse creates a  
DOM node for the <include> element. The two DOM instances can be  
compared to find the nodes in the first parse that correspond to  
<include> elements in the second parse.

Is there a better way?

Thanks - Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: xml include

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
It's not quite so simple. You basically need to write your own XInclude
processor to "fetch the referenced documents", resolve XPointers,
fallbacks, etc... if you were going to go that route.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

keshlam@us.ibm.com wrote on 09/16/2009 12:40:24 PM:

> Parse without XInclude processing, walk the tree to find the
> XIncludes, fetch the referenced documents and attach them to the
> include element?
>
> ______________________________________
> "... Three things see no end: A loop with exit code done wrong,
> A semaphore untested, And the change that comes along. ..."
>  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (http://www.ovff.
> org/pegasus/songs/threes-rev-11.html)
>
> Mark Brucks <br...@charter.net> wrote on 09/16/2009 12:22:41 PM:
>
> > Mark Brucks <br...@charter.net>
> > 09/16/2009 12:22 PM
> >
> > Please respond to
> > j-users@xerces.apache.org
> >
> > To
> >
> > j-users@xerces.apache.org
> >
> > cc
> >
> > Subject
> >
> > xml include
> >
> > I would like to know which elements in a document exist as a result of

> > XInclude processing and I need to retrieve the original <include>
> > element so that I have access to the entire set of attributes.
> >
> > My only solution, which I don't like, involves parsing the document
> > twice.  The first parse sets the xinclude feature of the DOMParser
> > (actually, of the underlying XIncludeAwareParserConfiguration), the
> > second parse has that feature turned off. The second parse creates a
> > DOM node for the <include> element. The two DOM instances can be
> > compared to find the nodes in the first parse that correspond to
> > <include> elements in the second parse.
> >
> > Is there a better way?
> >
> > Thanks - Mark
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> > For additional commands, e-mail: j-users-help@xerces.apache.org

Re: xml include

Posted by ke...@us.ibm.com.
Parse without XInclude processing, walk the tree to find the XIncludes, 
fetch the referenced documents and attach them to the include element?

______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (
http://www.ovff.org/pegasus/songs/threes-rev-11.html)

Mark Brucks <br...@charter.net> wrote on 09/16/2009 12:22:41 PM:

> Mark Brucks <br...@charter.net> 
> 09/16/2009 12:22 PM
> 
> Please respond to
> j-users@xerces.apache.org
> 
> To
> 
> j-users@xerces.apache.org
> 
> cc
> 
> Subject
> 
> xml include
> 
> I would like to know which elements in a document exist as a result of 
> XInclude processing and I need to retrieve the original <include> 
> element so that I have access to the entire set of attributes.
> 
> My only solution, which I don't like, involves parsing the document 
> twice.  The first parse sets the xinclude feature of the DOMParser 
> (actually, of the underlying XIncludeAwareParserConfiguration), the 
> second parse has that feature turned off. The second parse creates a 
> DOM node for the <include> element. The two DOM instances can be 
> compared to find the nodes in the first parse that correspond to 
> <include> elements in the second parse.
> 
> Is there a better way?
> 
> Thanks - Mark
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
> 

Re: xml include

Posted by Michael Ludwig <mi...@gmx.de>.
Mark Brucks schrieb am 16.09.2009 um 09:22:41 (-0700):
> I would like to know which elements in a document exist as a result of
> XInclude processing and I need to retrieve the original <include>
> element so that I have access to the entire set of attributes.
> 
> My only solution, which I don't like, involves parsing the document
> twice. [...]

> Is there a better way?

If you process the document using XSLT 2.0 or XQuery, you can use the
XPath 2.0 base-uri() function to find out the base URI for the node.
This takes into account assemblage by external entities and XInclude.
See the following example.

G:\dev\XSLT2 :: type base-uri.xml
<!DOCTYPE BaseUriTest [
<!ENTITY bla SYSTEM "some.ent">
]>
<BaseUriTest>
        <Elm/>
        &bla;
        <Elm/>
        <AnotherElm/>
</BaseUriTest>

G:\dev\XSLT2 :: type some.ent
<Eins/>
<Zwei/>
<Drei/>

G:\dev\XSLT2 :: more /t2 base-uri.xsl
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:template match="*">
    <xsl:value-of select="concat( base-uri(), '&#9;', name(), '&#10;')"/>
    <xsl:apply-templates select="*"/>
  </xsl:template>
</xsl:stylesheet>

G:\dev\XSLT2 :: saxon9 base-uri.xml base-uri.xsl
file:/G:/dev/XSLT2/base-uri.xml BaseUriTest
file:/G:/dev/XSLT2/base-uri.xml Elm
file:/G:/dev/XSLT2/some.ent     Eins
file:/G:/dev/XSLT2/some.ent     Zwei
file:/G:/dev/XSLT2/some.ent     Drei
file:/G:/dev/XSLT2/base-uri.xml Elm
file:/G:/dev/XSLT2/base-uri.xml AnotherElm

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org