XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
[Summary] A little experiment to compare external entities andXInclude

Hi Folks,

Thanks Ken Holman, Michael Glavassevich, and Michael Kay 
for your excellent answers. Below is a summary of the discussion. 
Please correct any errors I may have made.  /Roger



Here is an XML document that declares and then uses an external entity:

-----------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE BookStore [
    <!ENTITY Siddhartha SYSTEM "Siddhartha.xml">
]>
<BookStore>
        
    &Siddhartha;

</BookStore>
-----------------------------------------------

This is called an external entity declaration:

    <!ENTITY Siddhartha SYSTEM "Siddhartha.xml">

The external file is Siddhartha.xml. In the example the external file is local. However, the external file may be either local or on the network.

This is called an entity reference:

    &Siddhartha;

I dragged and dropped the XML document into Internet Explorer. The browser resolved the external entity reference (i.e., the browser replaced the entity reference by the content of Siddhartha.xml). This is what I saw on the screen:

<?xml version="1.0" ?> 
<!DOCTYPE BookStore (View Source for full doctype...)> 
<BookStore>
    <Book>
       <Title>Siddhartha</Title> 
       <Author>Hermann Hess</Author> 
       <Date>1951</Date> 
       <ISBN>0-553-20884-5</ISBN> 
       <Publisher>Bantam Books</Publisher> 
    </Book>
</BookStore>


Here is an XML document that uses XInclude to pull in the same Siddhartha.xml document:

-----------------------------------------------
<?xml version="1.0"?>
<BookStore xmlns:xi="http://www.w3.org/2001/XInclude";>

    <xi:include href="Siddhartha.xml" parse="xml">
        <xi:fallback />
    </xi:include>

</BookStore>
-----------------------------------------------

I dragged and dropped it into Internet Explorer. The browser did NOT resolve the XInclude reference (i.e., the <xi:include> element was NOT replaced by the contents of Siddhartha.xml). I saw no change on the screen.

I repeated the experiment with the Firefox browser and it exhibited the same behavior as Internet Explorer.


EXPLANATION

External entities are part of the XML specification. Thus, external entities are resolved by the XML parser. All XML parsers must support external entities. So, the XML parser in IE and in Firefox resolved the external entity reference.

XInclude is not part of the XML specification. It is a separate specification. <xi:include> elements are resolved by an XInclude processor. IE and Firefox do not come bundled with an XInclude processor. So, the <xi:include> element was not resolved.

An XInclude processor can be positioned anywhere in a processing pipeline. This is one of its benefits over external entities. For example, you can do XSLT transformations or XML Schema validation on an XML document before applying the includes:

    XML --> XML Parser --> XSLT transform

    XML --> XML Parser --> XSD validation

... or after applying the includes:

    XML --> XML Parser --> XInclude --> XSLT transform

    XML --> XML Parser --> XInclude --> XSD validation

In SAXON, if you want the latter (i.e., you want XInclude to be run before XSLT transformation), then you must set this flag when you invoke SAXON: -xi:on

Xerces-J and Xerces-C++ come bundled with an XInclude processor. 




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS