473,837 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(
CompensationPac kage))).Deseria lize(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(d oc)
o = (New XmlSerializer( GetType(
CompensationPac kage))).Deseria lize(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"?>
<CompensationPa ckage 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="u rn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSe t" msdata:IsDataSe t="true">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<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:diffgra m
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="u rn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet>
<Salary diffgr:id="Sala ry1" msdata:rowOrder ="0">
<_x0030_>2200 0</_x0030_>
<_x0031_>2332 0</_x0031_>
<_x0032_>2464 0</_x0032_>
<_x0033_>2596 0</_x0033_>
<_x0034_>2728 0</_x0034_>
<_x0035_>2904 0</_x0035_>
</Salary>
<Salary diffgr:id="Sala ry2" msdata:rowOrder ="1">
<_x0030_>2266 0</_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>
</CompensationPac kage>

Thanks,

Sam

Nov 21 '05 #1
4 3574
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.m icrosoft.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("outpu t.xml");

StringReader sr = new StringReader(do c.OuterXml);
MyDataSet ds = serializer.Dese rialize(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
570
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 the file that is on disk and attempts to deserialize it and create a new object. The process works fine if I serialize/deserialize in the first
2
9548
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> <Notes> some notes </Notes> </Report> <Report> blah blah blah </Report>
5
11675
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 simple, but complete example?
0
1499
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 show what goes in this root element) contains: <xs:element name= "ImageBox" type="ns:ImageBox_t" form="qualified" /> I use a validating reader to pull this into an XmlDocument. Then, step
0
1775
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
1879
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
5125
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 version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:myns="uri:myschema" targetNamespace="uri:myschema" elementFormDefault="qualified" version="1.0"> <xs:complexType name="derivedProperty">
0
1915
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"> <SQLQueryResult> <ObjectRef id="urn:uuid:425cb4ea-752c-4276-ae52-db295e8e7dc4" /> <ObjectRef id="urn:uuid:d9769b84-c48e-4381-bfd2-fe6e5c67cfc7" /> </SQLQueryResult> </AdhocQueryResponse> </RegistryResponse>
0
2257
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(); formatter.Serialize(stream, this); }
0
9843
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10875
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10566
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10623
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7001
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5669
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5848
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4040
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3124
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.