473,396 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XML deserialize Stream works ok but deserialize from XmlNodeReader fails


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

Nov 21 '05 #1
4 3545
Hi Sam,

Thanks for your posting. Regarding on the problem you mentioned, I've also
done some tests on myside and did found the problem you mentioned. It seems
that when deserializing such a typed dataset through the XmlNodeReader,
we'll lose the Table elements. Currently I'm doing some further research to
see whether this is a known issue or can be resolved, I'll update you as
soon as I got any new info.
Thanks for your understanding.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 21 '05 #2
Hi Sam,

Sorry for keeping you waiting. After some further research, the problem
when deserializing DataSet through a XmlNodeReader does due to an exsiting
issue. Your expected result that all the XmlReader's concrete derived class
should work is reasonable. And our dev guys plans to fix the problem in the
whidbey version of the .net framework. Currently we may need to use other
XmlReader to workaround this. I'm sorry for any inconvenience it brings
you.

Thanks & Regards,
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 21 '05 #3
Steven,

Thanks for the aditional information but it doesn't really help with
the problem now. I can't wait for the next version of the framework
for my program.

Can you tell me exactly where the problem lies, how it was fixed in
widbey, and point me towards a work-around in the current framework?
Is there another XmlReader that can read a document already in memory
or do I need to write the document out as a sting or text stream and
re-parse it, which would very waisteful.

Thanks,

Sam
On Mon, 07 Feb 2005 01:29:40 GMT, v-******@online.microsoft.com
(Steven Cheng[MSFT]) wrote:
Hi Sam,

Sorry for keeping you waiting. After some further research, the problem
when deserializing DataSet through a XmlNodeReader does due to an exsiting
issue. Your expected result that all the XmlReader's concrete derived class
should work is reasonable. And our dev guys plans to fix the problem in the
whidbey version of the .net framework. Currently we may need to use other
XmlReader to workaround this. I'm sorry for any inconvenience it brings
you.

Thanks & Regards,
Steven Cheng
Microsoft Online Support


Nov 21 '05 #4
Hi Samuel,

Thanks for your followup. The problem with currently XmlSerializer seems
caused by something incorrect when handling the namespace prefix (using the
xmlNodeReader).

Currently, one workaround is to use a StringReader to wrapper the
Node.OuterXml and deserialize on the StringREader rather than the
XmlNodeReader( for DataSet Type).
For example:

XmlDocument doc = new XmlDocument();
doc.Load("output.xml");

StringReader sr = new StringReader(doc.OuterXml);
MyDataSet ds = serializer.Deserialize(sr) as MyDataSet;

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Carl Mercier | last post by:
Hi! I have 2 different applications/assembly. The first one creates an object and serializes it to a textfile on disk. The second one has the the exact same class (copied/pasted). It reads...
2
by: Greg | last post by:
I'm writing a class in C# .... I have a collection calls Reports made up of Report objects. I'm trying to deserialize an XML file that looks like : <Reports> <Report> <Title>some title</Title>...
5
by: Geoff | last post by:
Is it possible to pull a single node (element) out of a complex XML file, using SelectSingleNode(), and then deserialize that node to an object? Could someone please post, or point me to, a...
0
by: JMD | last post by:
I have a set of schemas for two different XML files that share common structures through the use of "import". Eventually, the main XSD file (which just gathers pieces from the common stuff to...
0
by: Fred Heida | last post by:
Hi Al, i have a funny problem.. i you can call it funny.. what i have is 2 assemblies, the first one does nothing other then Application.Run(new MyForm())
17
by: Peter | last post by:
How would would you deserialize this example below? Imports System Imports System.Collections Imports System.IO Imports System.Xml.Serialization Public Class App1 Shared Sub Main()
1
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml...
0
by: anchiang | last post by:
Hi All, I have XML: <RegistryResponse status="Success" xmlns="urn:oasis:names:tc:ebxml-regrep:registry:xsd:2.1"> <AdhocQueryResponse xmlns="urn:oasis:names:tc:ebxml-regrep:query:xsd:2.1"> ...
0
by: connectpalm03-forum | last post by:
I have a class named (MyClassA) in ControlClasses.dll and was able to serialize it to database. Like below SaveTo(MemoryStream stream) { IFormatter formatter = new BinaryFormatter(); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.