[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

[Summary] A little experiment to compare external entities andXInclude

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Mon, 16 Aug 2010 13:08:35 -0400

[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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.