By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Problem deserializing XML data with xsd.exe

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.