XInclude.NET

In the night I develop some tests about the features of XInclude.NET. This package is a good implementation of XInclude 1.0 Working Draft. It also adds support for some XPointer features.

We begin with the XML document to be included in other documents.

<?xml version="1.0" encoding="UTF-8"?>
<IncludeList>
<Item name="Item_N1">Item_V1</Item>
<Item name="Item_N2">Item_V2</Item>
</IncludeList>

Now we creates a simple document in which embed the above XML

<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xi="http://www.w3.org/2003/XInclude">
<FirstChild>Ch1</FirstChild>
<xi:include href="SecondDoc.xml"/>
</Root>

Include a document is as simple as declare an include element. Now if we want to restrict the XML nodes to be include we put an XPath filter using XPointer.

<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xi="http://www.w3.org/2003/XInclude">
<FirstChild>Ch1</FirstChild>
<xi:include href="SecondDoc.xml" xpointer="xpointer(//IncludeList/Item[@name = 'Item_N1'])"/>
</Root>

All the XInclude features are perfectly defined in its specification. Using XInclude.NET we can now adds XInclude facilities to our .NET applications. The main class for working with the documents is XIncludingReader. The following code shws the three line basics to loads a document that make use of XInclude.

XmlReader reader = new XIncludingReader(new XmlTextReader(DocPath));
XmlDocument XDoc = new XmlDocument();
XDoc.Load(reader);

 

1 Comment

Comments have been disabled for this content.