473,698 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlSerializer & external XML document

I get an XmlDocument from an external source.
I want to load it/map it to C# class.

I'm creating classes as I learn about the format. many tag are yet unparsed,
but that seems ok for the XmlSerializer, great!

Now here is my problem.

let say my document conceptually map to classes like that:
public class Foo
{
public string Something;
}
public class Bar
{
public Foo Foo1;
public Foo Foo2;
public List<Foo> ListFoo1;
public List<Foo> ListFoo2;
}

the problem is it's write this way:
<bar>
<foo1>
<something>lala la</something>
</foo1>
<foo2>
<Foo>
<something>lala la</something>
</Foo>
</foo2>
<ListFoo1>
<Foo>
<something>lala la</something>
</Foo>
<Foo>
<something>lala la</something>
</Foo>
<!-- ... etc .. -->
</ListFoo1>
<ListFoo2>
<afoo>
<Foo>
<something>lala la</something>
</Foo>
</afoo>
<!-- ... etc .. -->
</ListFoo2>
</bar>

as you could see. a class / property is some time:
- just tagged with its name <myprop><!-- value --></myprop>
- or 2 tagged, with the class inside <myprop><Foo> <!--
value --></Foo></myprop>

kind of similar for the array where it's
- sometimes array of class:
<ListFoo1><Foo> <!-- content --></Foo> ...</ListFoo1>
- or some other times there is a named wrapper as in
<ListFoo2><afoo ><Foo><!-- content --> </Foo></afoo> .... </ListFoo2>
Fortunately, the behavior is fixed for a given property! (of course)

Now how could I use read/write C# class from/to this kind of XmlDocument
with minimum effort?
what kind of class/attributes/etc should I use?

Thanks for any tips!
Nov 12 '05 #1
1 1252
almost there...
I'm writting my own XmlSerializer.
That will do!

Except maybe performance wise, but it won't be intensive use, will see...

"Lloyd Dupont" <net.galador@ld > wrote in message
news:ux******** *****@TK2MSFTNG P15.phx.gbl...
I get an XmlDocument from an external source.
I want to load it/map it to C# class.

I'm creating classes as I learn about the format. many tag are yet
unparsed, but that seems ok for the XmlSerializer, great!

Now here is my problem.

let say my document conceptually map to classes like that:
public class Foo
{
public string Something;
}
public class Bar
{
public Foo Foo1;
public Foo Foo2;
public List<Foo> ListFoo1;
public List<Foo> ListFoo2;
}

the problem is it's write this way:
<bar>
<foo1>
<something>lala la</something>
</foo1>
<foo2>
<Foo>
<something>lala la</something>
</Foo>
</foo2>
<ListFoo1>
<Foo>
<something>lala la</something>
</Foo>
<Foo>
<something>lala la</something>
</Foo>
<!-- ... etc .. -->
</ListFoo1>
<ListFoo2>
<afoo>
<Foo>
<something>lala la</something>
</Foo>
</afoo>
<!-- ... etc .. -->
</ListFoo2>
</bar>

as you could see. a class / property is some time:
- just tagged with its name <myprop><!-- value --></myprop>
- or 2 tagged, with the class inside <myprop><Foo> <!--
value --></Foo></myprop>

kind of similar for the array where it's
- sometimes array of class:
<ListFoo1><Foo> <!-- content --></Foo> ...</ListFoo1>
- or some other times there is a named wrapper as in
<ListFoo2><afoo ><Foo><!-- content --> </Foo></afoo> .... </ListFoo2>
Fortunately, the behavior is fixed for a given property! (of course)

Now how could I use read/write C# class from/to this kind of XmlDocument
with minimum effort?
what kind of class/attributes/etc should I use?

Thanks for any tips!

Nov 12 '05 #2

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

Similar topics

13
6348
by: rbronson1976 | last post by:
Hi all, I have a very simple page that Firefox has problems with: www.absolutejava.com/testing.htm First of all, this page seems to be perfectly valid XHTML Strict. Both the W3C validator as well as Page Valet indicate it is valid. The page is being served with the proper MIME type of "application/xhtml+xml". Unfortunately, Firefox will not display the page due to a non-breaking
5
5416
by: Stuart Robertson | last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not create duplicate XML representations of the shared object, but instead use IDREFs to refer to the shared object. The XML I'm trying to produce is as follows (where "href" is an IDREF): <?xml version="1.0" encoding="utf-8"?> <MyRootClass...
0
3025
by: keith bannister via .NET 247 | last post by:
(Type your message here) -------------------------------- From: keith bannister Hi, I'm new to .net (as of last week) but here goes. I want to serialize/deserialize a file the conforms to an XML schema (xsd).
5
7284
by: Keith Bannister | last post by:
I'm new to .net so here goes. I'm tying to deserialize a class that is associated with an XML schema. I created the C# class with xsd.exe as below: xsd.exe /c /n:somenamespace properties.xsd this creates properties.cs
12
8491
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too. I, too, am getting nasty FileNotFound exceptions. I've read, and digested the article, and I think I've found a bug -- it's difficult to track, though it does happen often.
0
2293
by: William Stacey [MVP] | last post by:
Had a method that got some string info from mp3 tags in N files and serializes this class and deserializes at other side. Works ok except sometimes get chars that choke the XmlSerializer. After some digging, I found XmlSerializer chokes on 0x03 chars. It probably chokes on many others, but this one I found. It serializes ok, but chokes on deserialize on "<Field1>&#x3;</Field1>". So the questions are: 1) Why does serializer produce...
1
2085
by: SteveB | last post by:
I'm porting an application from Apache Xerces to .Net and am having a couple of small problems with deserialization. The XML that I'm reading comes from a variety of sources, and there are two inconsistencies that Xerces is able to handle that XmlSerializer seems not to be able to deal with. 1) Some of the boolean values that I'm dealing with are "True" and "False" rather than "true" and "false". I'm not quite sure whether "True" and...
0
5569
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
8671
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
8598
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9016
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
8887
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
7709
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4613
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
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
2
2321
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
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.