Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Deserialation of XML with abstreact element and import (XSD generated class)

From: "Michael Schöller" <michael.schoeller@-------.---.-->
To: NULL
Date: 11/12/2008 12:41:00 PM
Sorry I truncated to much. The Schema is not serializable (with xsd). For 
the test just change
<xs:element name="Application" type="ApplicationElt"> 
maxOccurs="unbounded"/>
to
<xs:element name="Application" type="ApplicationElt" maxOccurs="1" 
minOccurs="1"/>
Than you can try this test yourself.

Michael

"Michael Schöller" <michael.schoeller@i...> schrieb im Newsbeitrag 
news:%2337vbNLRJHA.4680@T......
> 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
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent