S
Samuel R. Neff
I'm deserializing an XML file. If I pass a Stream to the file
directly to the deserializer as follows it works fine:
o = (New XmlSerializer( GetType(
CompensationPackage))).Deserialize(stream)
But if I pass an XmlNodeReader to the deserializer it doesn't work:
Dim doc As New XmlDocument
doc.Load(stream)
Dim reader As New XmlNodeReader(doc)
o = (New XmlSerializer( GetType(
CompensationPackage))).Deserialize(reader)
The problem that occurs is that the XML file has a DataSet inside it
(within a large object hierarchy--it's not just a dataset) and when I
deserialize via an XmlNodeReader the DataSet comes through without any
tables. It exists, but the data isn't there.
The reason I want to use an XmlNodeReader instead of just using the
Stream directly is I need to read one of the root attributes first to
verify the version before attempting to deserialize (run a transform
if it's an old version, reject if it's too new).
Here's a heavily snipped version of the xml file...
<?xml version="1.0" encoding="utf-8"?>
<CompensationPackage xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<InternalTables>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Salary">
<xs:complexType>
<xs:sequence>
<xs:element name="_x0030_" type="xs:double"
minOccurs="0" />
<xs:element name="_x0031_" type="xs:double"
minOccurs="0" />
<xs:element name="_x0032_" type="xs:double"
minOccurs="0" />
<xs:element name="_x0033_" type="xs:double"
minOccurs="0" />
<xs:element name="_x0034_" type="xs:double"
minOccurs="0" />
<xs:element name="_x0035_" type="xs:double"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet>
<Salary diffgr:id="Salary1" msdata:rowOrder="0">
<_x0030_>22000</_x0030_>
<_x0031_>23320</_x0031_>
<_x0032_>24640</_x0032_>
<_x0033_>25960</_x0033_>
<_x0034_>27280</_x0034_>
<_x0035_>29040</_x0035_>
</Salary>
<Salary diffgr:id="Salary2" msdata:rowOrder="1">
<_x0030_>22660</_x0030_>
<_x0031_>24019.6</_x0031_>
<_x0032_>25379.2</_x0032_>
<_x0033_>26738.8</_x0033_>
<_x0034_>28098.4</_x0034_>
<_x0035_>30346.8</_x0035_>
</Salary>
</NewDataSet>
</diffgr:diffgram>
</InternalTables>
</SalarySchedule>
</CompensationPackage>
Thanks,
Sam
directly to the deserializer as follows it works fine:
o = (New XmlSerializer( GetType(
CompensationPackage))).Deserialize(stream)
But if I pass an XmlNodeReader to the deserializer it doesn't work:
Dim doc As New XmlDocument
doc.Load(stream)
Dim reader As New XmlNodeReader(doc)
o = (New XmlSerializer( GetType(
CompensationPackage))).Deserialize(reader)
The problem that occurs is that the XML file has a DataSet inside it
(within a large object hierarchy--it's not just a dataset) and when I
deserialize via an XmlNodeReader the DataSet comes through without any
tables. It exists, but the data isn't there.
The reason I want to use an XmlNodeReader instead of just using the
Stream directly is I need to read one of the root attributes first to
verify the version before attempting to deserialize (run a transform
if it's an old version, reject if it's too new).
Here's a heavily snipped version of the xml file...
<?xml version="1.0" encoding="utf-8"?>
<CompensationPackage xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<InternalTables>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Salary">
<xs:complexType>
<xs:sequence>
<xs:element name="_x0030_" type="xs:double"
minOccurs="0" />
<xs:element name="_x0031_" type="xs:double"
minOccurs="0" />
<xs:element name="_x0032_" type="xs:double"
minOccurs="0" />
<xs:element name="_x0033_" type="xs:double"
minOccurs="0" />
<xs:element name="_x0034_" type="xs:double"
minOccurs="0" />
<xs:element name="_x0035_" type="xs:double"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet>
<Salary diffgr:id="Salary1" msdata:rowOrder="0">
<_x0030_>22000</_x0030_>
<_x0031_>23320</_x0031_>
<_x0032_>24640</_x0032_>
<_x0033_>25960</_x0033_>
<_x0034_>27280</_x0034_>
<_x0035_>29040</_x0035_>
</Salary>
<Salary diffgr:id="Salary2" msdata:rowOrder="1">
<_x0030_>22660</_x0030_>
<_x0031_>24019.6</_x0031_>
<_x0032_>25379.2</_x0032_>
<_x0033_>26738.8</_x0033_>
<_x0034_>28098.4</_x0034_>
<_x0035_>30346.8</_x0035_>
</Salary>
</NewDataSet>
</diffgr:diffgram>
</InternalTables>
</SalarySchedule>
</CompensationPackage>
Thanks,
Sam