Hi all;
I'm encountering a problem using the Mvp.Xml.XInclude.XIncludingReader class to populate a strongly-typed dataset. When the XML data file contains xinclude elements, those included elements are not read into the dataset if I pass an XIncludingReader instance to DataSet.ReadXml.
I'm using .NET 1.1, VS.NET 2003, and a locally-built version of the 1.3 Mvp.Xml.XInclude codebase. You can use the following files to reproduce the issue:
//Class1.cs
class Class1{ static void Main(string[] args) { Dataset1 data = new Dataset1(); Mvp.Xml.XInclude.XIncludingReader reader = new Mvp.Xml.XInclude.XIncludingReader( args[ 0 ] ); data.ReadXml( reader );
foreach( Dataset1.Table1Row row in data.Table1 ) { Console.WriteLine( "{0} = {1}", row.name, row.value ); } }}
// Dataset1.xsd
<?xml version="1.0" encoding="utf-8" ?><xs:schema id="Dataset1" targetNamespace="http://tempuri.org/Dataset1.xsd" elementFormDefault="qualified" attributeFormDefault="qualified" xmlns="http://tempuri.org/Dataset1.xsd" xmlns:mstns="http://tempuri.org/Dataset1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="Dataset1" msdata:IsDataSet="true"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="Table1"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string" minOccurs="0" /> <xs:element name="value" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element></xs:schema>
// data.xml:
<Dataset1 xmlns="http://tempuri.org/Dataset1.xsd"> <include xmlns="http://www.w3.org/2001/XInclude" href="data2.xml" xpointer="xmlns(d=http://tempuri.org/Dataset1.xsd)xpointer(//d:Table1)" parse="xml" />
<Table1> <name>item1</name> <value>inline item</value> </Table1></Dataset1>
// data2.xml
<Dataset1 xmlns="http://tempuri.org/Dataset1.xsd"> <Table1> <name>item2</name> <value>included item</value> </Table1></Dataset1>
If you pass "data.xml" to the executable you will see that only the data rows included in the data.xml file are incorporated into the DataSet; the items in data2.xml are "ignored".
Pre-loading the XML into an XmlDocument resolves the issue; for example, this code:
class Class1{ static void Main(string[] args) { Dataset1 data = new Dataset1(); System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
Mvp.Xml.XInclude.XIncludingReader reader = new Mvp.Xml.XInclude.XIncludingReader( args[ 0 ] ); doc.Load( reader );
data.ReadXml( new System.Xml.XmlNodeReader( doc.DocumentElement ) );
will process data.xml properly and output all items from data.xml and the included data2xml. I would rather avoid this overhead if possible.
Any pointers or suggestions? Any chance I'm using the XIncludingReader incorrectly?
Obliged,
beefarino.