Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Deserialation of XML with abstreact element and import (XSD generated class) [Thread Next] Re: Deserialation of XML with abstreact element and import (XSD generated class)To: NULL Date: 11/12/2008 1:10:00 PM Sorry I fond a little mistake.
Ic you serialize the class you do get
<?xml version="1.0"?>
<MyFile xmlns="http://mynamespace"
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance>
<Application>
<Message xmlns:q1="http://mynamespace/reporting">
<q1:Text>Fantasy</q1:Text>
</Message>
</Application>
</MyFile>
S the difference is
<Message xmlns:q1="http://mynamespace/reporting">
to
<Reporting xmlns="http://mynamespace/reporting">
Both versions are valid but only the first one deserialize correctly. I
think both sould work, however since I cannot change the XML File how can I
get the second version to work.
Thanks
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
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
