473,406 Members | 2,259 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,406 software developers and data experts.

Problem deserializing XML data with xsd.exe

Hi everyone,

I'm trying to read an xml config file in C#. To do this, I have used the
xsd.exe tool to create an xsd file from my xml, and to generate code to
read this xml file.

Here is a small sample of my xml file:
<feed>
<location>
<directory>data</directory>
</location>
<files>
<file>
<name>name</name>
</file>
</files>
</feed>

Whereas I'm able to read the directory value correctly, I cannot read the
value of name. After some searching, and after modifying the code a bit,
I found that the value for name wasn't even filled in the first place!

A coworker told me to look for problems with nested xsd's in Google, but
I was unable to find something useful.

The only thing I seem to be able to find, is an empty array of "file"
objects, which is not what I need (besides, there is one in the xml
file).

Can somebody point me in the right direction? Why is name not read during
the process of deserialization?

Thanks in advance,

JayCee
--
http://jcsnippets.atspace.com
a collection of source code, tips and tricks
Mar 15 '06 #1
1 2310
JayCee,

You just hit a known bug.

<feed>
<location>
<directory>data</directory>
</location>
<files>
<file>
<name>name</name>
</file>
</files>
</feed>

On this XML file, at the part:
<files>
<file>
<name>name</name>
</file>
</files>

You are creating a complextype data files, that has no leaf nodes, the
serializer has a bug that loses the data.

In order to overcome this, avoid having complex types with no elements, so
to correct this you can change your structure to:

<feed>
<location>
<directory>data</directory>
</location>
<files>
<someField>any value</someField>
<file>
<name>name</name>
</file>
</files>
</feed>

Create the xsd file by xsd.exe, and then create the classes by xsd.exe /c
and use the class to deserialize the xml file above.

I hope it helps,

--
Sinan Ussakli [MSFT]
WebData XML
Microsoft
"jcsnippets.atspace.com" wrote:
Hi everyone,

I'm trying to read an xml config file in C#. To do this, I have used the
xsd.exe tool to create an xsd file from my xml, and to generate code to
read this xml file.

Here is a small sample of my xml file:
<feed>
<location>
<directory>data</directory>
</location>
<files>
<file>
<name>name</name>
</file>
</files>
</feed>

Whereas I'm able to read the directory value correctly, I cannot read the
value of name. After some searching, and after modifying the code a bit,
I found that the value for name wasn't even filled in the first place!

A coworker told me to look for problems with nested xsd's in Google, but
I was unable to find something useful.

The only thing I seem to be able to find, is an empty array of "file"
objects, which is not what I need (besides, there is one in the xml
file).

Can somebody point me in the right direction? Why is name not read during
the process of deserialization?

Thanks in advance,

JayCee
--
http://jcsnippets.atspace.com
a collection of source code, tips and tricks

Mar 22 '06 #2

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

Similar topics

1
by: Ursula Peter-Czichi | last post by:
I have not planned data persistence at the beginning of a larger project. This now causes some problems. Doing some tests, I have figured out how to serialize and deserialize simple variables as...
1
by: Thomas | last post by:
Hi, I implemented a composite pattern which should be serializable to xml. After spending some time in the newsgroups, i finally managed serializing, even with utf-8 instead of utf-16, which...
4
by: Wayne Wengert | last post by:
Using VB.NET I want to read in an XML file that has an array of objects and then step through the resulting array in code. I build a class to define the structure and I am running code to read in...
2
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string...
6
by: Steve Teeples | last post by:
I use serialization to write class data to a file. During my development of this class I need to add properties or fields on occation. After adding a property, when deserializing the data saved...
4
by: Andrew E Chapman | last post by:
What happens to an object which is not nothing has another object deserialized into it? I assume that the data in it is completely destroyed by the new object. I am interested because I have...
6
by: Picho | last post by:
Hi all. I have a webservice and a windows app. both of them reference the same class library called WebServiceTest.Core that defines a class called Class1. the webservice exposes a method...
10
by: Bryce Calhoun | last post by:
Hello, First of all, this is a .NET 1.1 component I'm creating. SUMMARY ----------------------- This component that I'm creating is, for all intents and purposes, a document parser (I'm...
9
by: norvinl | last post by:
Hi, I'm serializing a class and using shared memory / deserialization to send it to other processes. I can serialize with one app and deserialize with another instance of the same app. But...
0
by: Sivajee Akula | last post by:
Hello All, I am trying to consume a .NET Service from Adobe LiveCycle Workflow. The service deals with complex objects. I am getting the following exception at the time of invocation of the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.