all groups > dotnet xml > may 2005 >
You're in the

dotnet xml

group:

xs:anyAttribute XmlSerializer Bug


xs:anyAttribute XmlSerializer Bug Jeff T.
5/25/2005 11:00:35 AM
dotnet xml:
I am noticing some VERY odd behavior when serializing and deserializing
classes that were generate using the XSD.exe utility. Can anyone
confirm if this is a bug (or it I am just doing something I shouldn't!)

Basically what is happening is that if the schema contains a collection
of base types and the base type contains the xs:anyAttribute type, the
xsi:type attribute gets set twice for a single element. Here is an
example of the erroneous output:

<?xml version="1.0" encoding="utf-16"?>
<BaseCollection ... xsi:type="DerivedTypeCollection" >
<Collection>
<BaseTypes xsi:type="DerivedType1" d3p1:attr1="test1"
xsi:type="DerivedType1" d3p1:attr3="test3"
xmlns:d3p1="http://www.myns.com/bugtest" />
<BaseTypes xsi:type="DerivedType2" d3p1:attr1="test2"
xsi:type="DerivedType2" d3p1:attr2="test4"
xmlns:d3p1="http://www.myns.com/bugtest" />
</Collection>
</BaseCollection>

Notice that BaseTypes elements have TWO attributes for xsi:type!!!!!
This causes serialization to fail.

This occurs when I have XML data, deserialize it to an object
(generated by xsd.exe), and then serialize it back to XML again.

The schema for the above XML looks like:
<xs:complexType name="BaseType">
<xs:sequence></xs:sequence>
<xs:attribute name="attr1" type="xs:string" use="required"/>
<xs:anyAttribute /> <----------THIS CAUSES THE BUG
</xs:complexType>

<xs:complexType name="DerivedType1">
<xs:complexContent>
<xs:extension base="BaseType">
<xs:sequence></xs:sequence>
<xs:attribute name="attr3" type="xs:string" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

I can remove the anyAttribute for now, but I wanted in there originally
for flexibility. Is this a bug with XmlSerializer?

Thanks,
Jeff
Re: xs:anyAttribute XmlSerializer Bug Zafar Abbas [MSFT]
5/31/2005 10:12:54 AM
This is a known bug in XmlSerializer which might be addressed in .NET
Framework 2.0

[quoted text, click to view]

AddThis Social Bookmark Button