473,586 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlDeserialize problem

m96
hi,

i have a problem with XmlDeserilisati on which drives me crazy. i know i
must be missing something very trivial...

i'm trying to parse the folling xml file

i really would appreciate any help.

cheers...

===
<?xml version="1.0" ?>
<courses>
<course>
<title>title1 </title>
<remoteuri>remu ri</remoteuri>
<localuri>locur i</localuri>
<overwrite>pd f</overwrite>
</course>
<course>
<title>test2</title>
<remoteuri>renu ri</remoteuri>
<user>usernam e</user>
</course>
</courses>
===

with this code
===
using System;
using System.Collecti ons;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;

[XmlRoot("course s")]
public class MeList {
public course[] courses;
}

public class course {
public string title;
public string remoteuri;
public string localuri;
public string overwrite;
}

public class Run
{
public static void Main()
{
Run test = new Run();
test.Deserializ eObject("ad.xml ");
}

public void DeserializeObje ct(string filename)
{
FileStream fs = new FileStream(file name, FileMode.Open);
XmlSerializer x = new XmlSerializer(t ypeof(MeList));
MeList m = (MeList) x.Deserialize(f s);
Console.WriteLi ne("Members:") ;

Console.WriteLi ne("..{0}", m.courses.Lengt h);
foreach(course c in m.courses) { Console.WriteLi ne("....\t"
+ c.overwrite);}
}
}
====
Nov 17 '05 #1
4 3770
I think you have to declare [Serializable] in MeList, by the way,
what exact error did you get?

Jianwei

m96 wrote:
hi,

i have a problem with XmlDeserilisati on which drives me crazy. i know i
must be missing something very trivial...

i'm trying to parse the folling xml file

i really would appreciate any help.

cheers...

===
<?xml version="1.0" ?>
<courses>
<course>
<title>title1 </title>
<remoteuri>remu ri</remoteuri>
<localuri>locur i</localuri>
<overwrite>pd f</overwrite>
</course>
<course>
<title>test2</title>
<remoteuri>renu ri</remoteuri>
<user>usernam e</user>
</course>
</courses>
===

with this code
===
using System;
using System.Collecti ons;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;

[XmlRoot("course s")]
public class MeList {
public course[] courses;
}

public class course {
public string title;
public string remoteuri;
public string localuri;
public string overwrite;
}

public class Run
{
public static void Main()
{
Run test = new Run();
test.Deserializ eObject("ad.xml ");
}

public void DeserializeObje ct(string filename)
{
FileStream fs = new FileStream(file name, FileMode.Open);
XmlSerializer x = new XmlSerializer(t ypeof(MeList));
MeList m = (MeList) x.Deserialize(f s);
Console.WriteLi ne("Members:") ;

Console.WriteLi ne("..{0}", m.courses.Lengt h);
foreach(course c in m.courses) { Console.WriteLi ne("....\t" +
c.overwrite);}
}
}
====

Nov 17 '05 #2
m96
the error i get is the following:

Unhandled Exception: System.NullRefe renceException: Object reference not
set to an instance of an object.
at Run.Deserialize Object(String filename) in c:\Documents and
Settings\Admini strator\My Documents\tmp\t est.cs:line 34
at Run.Main() in c:\Documents and Settings\Admini strator\My
Documents\tmp\t est.cs:line 24

that means also (what i can see while debugging) that MeList.courses is
empty. that again means i'm declaring the objects somehow wrong so they
don't get filled by XmlDeserializer .

that prooves again i still haven't understood how that xmlserializer
works... argh.

thank you for the fast answer...


John Sun wrote:
I think you have to declare [Serializable] in MeList, by the way,
what exact error did you get?

Jianwei

m96 wrote:
hi,

i have a problem with XmlDeserilisati on which drives me crazy. i know
i must be missing something very trivial...

i'm trying to parse the folling xml file

i really would appreciate any help.

cheers...

===
<?xml version="1.0" ?>
<courses>
<course>
<title>title1 </title>
<remoteuri>remu ri</remoteuri>
<localuri>locur i</localuri>
<overwrite>pd f</overwrite>
</course>
<course>
<title>test2</title>
<remoteuri>renu ri</remoteuri>
<user>usernam e</user>
</course>
</courses>
===

with this code
===
using System;
using System.Collecti ons;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;

[XmlRoot("course s")]
public class MeList {
public course[] courses;
}

public class course {
public string title;
public string remoteuri;
public string localuri;
public string overwrite;
}

public class Run
{
public static void Main()
{
Run test = new Run();
test.Deserializ eObject("ad.xml ");
}

public void DeserializeObje ct(string filename)
{
FileStream fs = new FileStream(file name, FileMode.Open);
XmlSerializer x = new XmlSerializer(t ypeof(MeList));
MeList m = (MeList) x.Deserialize(f s);
Console.WriteLi ne("Members:") ;

Console.WriteLi ne("..{0}", m.courses.Lengt h);
foreach(course c in m.courses) { Console.WriteLi ne("....\t"
+ c.overwrite);}
}
}
====

Nov 17 '05 #3
m96 wrote:
the error i get is the following:

Unhandled Exception: System.NullRefe renceException: Object reference not
set to an instance of an object.
at Run.Deserialize Object(String filename) in c:\Documents and
Settings\Admini strator\My Documents\tmp\t est.cs:line 34
at Run.Main() in c:\Documents and Settings\Admini strator\My
Documents\tmp\t est.cs:line 24

that means also (what i can see while debugging) that MeList.courses is
empty. that again means i'm declaring the objects somehow wrong so they
don't get filled by XmlDeserializer .

that prooves again i still haven't understood how that xmlserializer
works... argh.

thank you for the fast answer...


John Sun wrote:
I think you have to declare [Serializable] in MeList, by the way,
what exact error did you get?

Jianwei

m96 wrote:
hi,

i have a problem with XmlDeserilisati on which drives me crazy. i know
i must be missing something very trivial...

i'm trying to parse the folling xml file

i really would appreciate any help.

cheers...

===
<?xml version="1.0" ?>
<courses>
<course>
<title>title1 </title>
<remoteuri>remu ri</remoteuri>
<localuri>locur i</localuri>
<overwrite>pd f</overwrite>
</course>
<course>
<title>test2</title>
<remoteuri>renu ri</remoteuri>
<user>usernam e</user>
</course>
</courses>
===

with this code
===
using System;
using System.Collecti ons;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;

[XmlRoot("course s")]
public class MeList {
public course[] courses;
}

public class course {
public string title;
public string remoteuri;
public string localuri;
public string overwrite;
}

public class Run
{
public static void Main()
{
Run test = new Run();
test.Deserializ eObject("ad.xml ");
}

public void DeserializeObje ct(string filename)
{
FileStream fs = new FileStream(file name, FileMode.Open);
XmlSerializer x = new XmlSerializer(t ypeof(MeList));
MeList m = (MeList) x.Deserialize(f s);
Console.WriteLi ne("Members:") ;

Console.WriteLi ne("..{0}", m.courses.Lengt h);
foreach(course c in m.courses) {
Console.WriteLi ne("....\t" + c.overwrite);}
}
}
====

Be honest to you, I am not sure how you can deserialize into the array,
what I will do will be loop through each node in the xml file, and
deserilize course object. Apply [Serializable] attribute on the course.

HTH

Jianwei
Nov 17 '05 #4
m96
found the solution; in case someone is interested in it.

xsd ad.xml
xsd /l:CS /c ad.xsd

generates the classes with which you can deserialize. actually very nice
and handy tool.

cheers.
John Sun wrote:
m96 wrote:
the error i get is the following:

Unhandled Exception: System.NullRefe renceException: Object reference
not set to an instance of an object.
at Run.Deserialize Object(String filename) in c:\Documents and
Settings\Admini strator\My Documents\tmp\t est.cs:line 34
at Run.Main() in c:\Documents and Settings\Admini strator\My
Documents\tmp\t est.cs:line 24

that means also (what i can see while debugging) that MeList.courses
is empty. that again means i'm declaring the objects somehow wrong so
they don't get filled by XmlDeserializer .

that prooves again i still haven't understood how that xmlserializer
works... argh.

thank you for the fast answer...


John Sun wrote:
I think you have to declare [Serializable] in MeList, by the way,
what exact error did you get?

Jianwei

m96 wrote:

hi,

i have a problem with XmlDeserilisati on which drives me crazy. i
know i must be missing something very trivial...

i'm trying to parse the folling xml file

i really would appreciate any help.

cheers...

===
<?xml version="1.0" ?>
<courses>
<course>
<title>title1 </title>
<remoteuri>remu ri</remoteuri>
<localuri>locur i</localuri>
<overwrite>pd f</overwrite>
</course>
<course>
<title>test2</title>
<remoteuri>renu ri</remoteuri>
<user>usernam e</user>
</course>
</courses>
===

with this code
===
using System;
using System.Collecti ons;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;

[XmlRoot("course s")]
public class MeList {
public course[] courses;
}

public class course {
public string title;
public string remoteuri;
public string localuri;
public string overwrite;
}

public class Run
{
public static void Main()
{
Run test = new Run();
test.Deserializ eObject("ad.xml ");
}

public void DeserializeObje ct(string filename)
{
FileStream fs = new FileStream(file name, FileMode.Open);
XmlSerializer x = new XmlSerializer(t ypeof(MeList));
MeList m = (MeList) x.Deserialize(f s);
Console.WriteLi ne("Members:") ;

Console.WriteLi ne("..{0}", m.courses.Lengt h);
foreach(course c in m.courses) {
Console.WriteLi ne("....\t" + c.overwrite);}
}
}
====


Be honest to you, I am not sure how you can deserialize into the array,
what I will do will be loop through each node in the xml file, and
deserilize course object. Apply [Serializable] attribute on the course.

HTH

Jianwei

Nov 17 '05 #5

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

Similar topics

0
3058
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in the context of a main window. The problem does not occur on HPUX or Linux. The following simple example code illustrates the problem and the...
11
3744
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class (ClassB* b; b->func(); ) the base-class function is called instead of the new function in the derived class. All other similar functions (virtual in...
0
2016
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent users So I designed the project as master Node that has all administration
117
7147
by: Peter Olcott | last post by:
www.halting-problem.com
0
1060
by: Bryan Ax | last post by:
I have an object that is being serialized via the XmlSerializer and stored in a database in xml format. Since initial creation, some of the properties of the object have changed (I have removed a few items that were initially in this object and put them into a separate object). The XmlDeserialize() method now is breaking, and my hunch is...
28
5194
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass(); .... and then call the virtual method, why is it that the base class's method is called instead of the overridden method? How do I fix this if I...
6
3793
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length is more that 1249 bytes, then the progress bar of the browser will move too slow and then displaying that the page not found!!!! If the message is...
16
4889
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be...
2
4541
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am...
0
7912
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...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
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...
1
7959
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...
0
3837
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...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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...

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.