>> English << | По-русскиZVON > Tutorials > XInclude Tutorial
>> Example 7 << | Prev | Next | Contents

Attribute encoding and parse="text"


Description

If the parse attribute of the include element is set to 'text', you may sometimes need to specify the encoding of the included document.

Valid example

The file a.xml includes whole file b.txt and specifies the encoding to be "iso-8859-1".
File a.xml:
    <a> 
     <xi:include href="b.txt" parse="text"
				encoding="iso-8859-1"
      xmlns:xi="http://www.w3.org/2001/XInclude"/>
    </a>
   

File b.txt was originally written in iso-8859-2 encoding.
File b.txt:
				ěščřžýáíé
			

Due to attribute encoding="iso-8859-1" the file b.txt is treated as written in iso-8859-1. The characters will be converted!
File a.xml after processing:
    <a>
     ì¹èø¾ýáíé
    </a>
   

Example with errors

If there is no external encoding information available, and the attribute encoding is missing, the encoding is determined as UTF-8. As the file b.txt is written in iso-8859-2, this will result into fatal error.
File a.xml:
    <a> 
     <xi:include href="b.txt" parse="text"
      xmlns:xi="http://www.w3.org/2001/XInclude"/>
    </a>