Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Deserialation of XML with abstreact element and import (XSD generated class) -- SOLUTION Deserialation of XML with abstreact element and import (XSD generated class)To: NULL Date: 11/12/2008 11:42:00 AM Hi,
I have a litte problem with an given xml-File. I've got the schema for this
file and generated an class with xsd.exe.
I have truncated and simlified the files so I hope it's all clear.
The xml-File comes in the format (FILE A)
---------------------------------------------------------------------------
<?xml version="1.0"?>
<MyFile xmlns="http://mynamespace"
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance>
<Application>
<Reporting xmlns="http://mynamespace/reporting">
<Text>Fantasy</Text>
</Reporting>
</Application>
</MyFile>
---------------------------------------------------------------------------
The xml-schema is defined as#
---------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://mynamespace"
xmlns:wcr="http://mynamespace/reporting" xmlns="http://mynamespace"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://mynamespace/reporting"
schemaLocation="mynamespace.Reporting.xsd"/>
<xs:element name="MyFile">
<xs:complexType>
<xs:sequence>
<xs:element name="Application" type="ApplicationElt"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ApplicationElt">
<xs:sequence>
<xs:element ref="Message" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Message" type="MessageBaseElt"/>
<xs:complexType name="MessageBaseElt" abstract="true"/>
</xs:schema>
---------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://mynamespace/reporting"
xmlns:wcb="http://mynamespace" xmlns="http://mynamespace/reporting"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://mynamespace"
schemaLocation="mynamespace.xsd"/>
<xs:complexType name="ReportingMessageElt">
<xs:complexContent>
<xs:extension base="wcb:MessageBaseElt">
<xs:sequence>
<xs:element name="Text" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Reporting" type="ReportingMessageElt"
substitutionGroup="wcb:Message"/>
</xs:schema>
---------------------------------------------------------------------------
If I try to serialize this class the file that is generatet looks like (FILE
B)
---------------------------------------------------------------------------
<?xml version="1.0"?>
<MyFile xmlns="http://mynamespace"
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance>
<Application>
<Reporting xmlns:q1="http://mynamespace/reporting">
<q1:Text>Fantasy</q1:Text>
</Reporting>
</Application>
</MyFile>
---------------------------------------------------------------------------
I tested both files with 3 different xml Validators and all files are valid.
However when deserializing FILE B all works well and after MyFile x =
(MyFile)serial.Deserialize(fs);
x.Application[0].Message[0] holds an Reporting object with the data.
When deserializing FILE A x.Application[0].Message is null and no exception
is raised that gives an hint to the Problem.
Did I do something wrong?
Just do be sure. There is nothing I can do about the xml-File (FILE A) so I
have to get this to work with changes in the generated class or the
xml-Schema.
Thanks
Michael
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
