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

XSD.exe question

P: n/a
Hi,

I have the following schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="TestItem">
<xs:complexType>
<xs:choice>
<xs:element name="my_string" type="xs:string"/>
<xs:element name="MyList">
<xs:complexType>
<xs:sequence>
<xs:element name="list_item" type="TestType"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="TestType">
<xs:sequence>
<xs:element name="first_item" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

Which XSD makes into the following .cs file:

using System.Xml.Serialization;
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class TestItem {

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("MyLi st",
typeof(TestType[]))]
[System.Xml.Serialization.XmlElementAttribute("my_s tring",
typeof(string))]
public object Item;
}

/// <remarks/>
public class TestType {

/// <remarks/>
public string first_item;
}

Which, when used serializes the data to:

<?xml version="1.0" encoding="utf-16"?>
<TestItem xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MyList>
<TestType>
<first_item>Hello</first_item>
</TestType>
<TestType>
<first_item>World</first_item>
</TestType>
</MyList>
</TestItem>

When I would expect:

<?xml version="1.0" encoding="utf-16"?>
<TestItem xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MyList>
<list_item>
<first_item>Hello</first_item>
</list_item>
<list_item>
<first_item>World</first_item>
</list_item>
</MyList>
</TestItem>

This is fairly easily fixable by editing the .cs file, however the XSD that
we are using is rather large and still evolving quite a bit. It would slow
things down tremendously. Does anyone have any insight as to why XSD is
doing what it is doing?

Thanks
Daryn
Dec 1 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.