473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

xsi:type and inherited classes

6
Hi I refer to an archived discussion titled inherited classes and xml.serialization

I seem to have the same situation, i have two classes B and C inheriting class A, class A includes both types B and C as seen below

<System.Xml.Serialization.XmlIncludeAttribute(GetT ype(B)), _
System.Xml.Serialization.XmlIncludeAttribute(GetTy pe(C))> _
Public MustInherit Class A
.....
end class

Problem is when i create an instance of class B and serialise it using XmlSerializer, the xsi:type is still missing and this is giving me an error when it comes to submitting the generated XML file as a request to a webservice.I want it to show <A xsi:type="B">

Can someone please guide me in the right direction or point out to me what im doing wrong?

Your help would be greatly appreciated

Thanks
Jul 12 '07 #1
8 2843
jkmyoung
2,057 Expert 2GB
I think you would have to explicitly cast it as a type B before you serialize it. If you're serializing as a class A, then it will only include type A details, leaving out anything from class B.

I'm not sure if this is what you're looking for.
Jul 12 '07 #2
chr
6
I think you would have to explicitly cast it as a type B before you serialize it. If you're serializing as a class A, then it will only include type A details, leaving out anything from class B.

I'm not sure if this is what you're looking for.

The details im serializing are fine i.e. those of type B my only problem is "xsi:type=" not being included in my output xml file. Any ideas please?
Jul 13 '07 #3
jkmyoung
2,057 Expert 2GB
Which method of serialize are you using, eg what object is the output going to?
Is it an XmlWriter? If so, could you post your code on how you set up the XmlWriter?
Jul 13 '07 #4
chr
6
I am outputting to a Text Writer

this is the code

Expand|Select|Wrap|Line Numbers
  1.  
  2.    Dim serializer As New XmlSerializer(RQ.GetType)
  3.    Dim writer As TextWriter
  4.    Dim strFileName As String
  5.  
  6.    strFileName = Server.MapPath("xml") & "\request_" & Session.SessionID.ToString & ".xml"
  7.         writer = New StreamWriter(strFileName)
  8.         serializer.Serialize(writer, RQ)
  9.         writer.Close()
  10.  
  11.  
now RQ is an instance of a class (which was auto generated using xsd tool and given schema) and one of its attributes is an instance of Class B mentioned above which inherits from class A. Is this what u are asking for?
Jul 16 '07 #5
chr
6
One thing i am wondering about is whether this is happening because the attribute in class RQ is actually of type B not of type A. Could this be? however when i change it to type A and i try to serialise i get the following error

The type namespace.B was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

i've googled this and i have added the xmlinclude over class A but nothing i keep getting the same error. Am i missing out on something?

thanks once again
Jul 16 '07 #6
jkmyoung
2,057 Expert 2GB
Not sure, but have you tried using an XmlTextWriter instead?
http://msdn2.microsoft.com/en-us/library/aa335857(VS.71).aspx
Jul 16 '07 #7
chr
6
yep i did but no change its still the same ...
Jul 18 '07 #8
chr
6
ok i found out that the problem is actually because of the new class D. In it it has an attribute of type Class A which i am setting to type class B before serializing

now when i create an instance of class B and serialise it (to type classA) i get <A xsi:type=B> but what i need to do is serialise to type class D and in it get <A xsi:type=B>

Basically my classes are

Expand|Select|Wrap|Line Numbers
  1. Class D 
  2.       dim attrB as A -> this should show as <A xsi:type=B>
  3.       other attributes ...
  4. end class 
  5.  
  6. [XmlIncludeAttribute(GetType(B)]
  7. Class A 
  8.   ....
  9. end class 
  10.  
  11. Class B : A 
  12.   ....
  13. end class 
now im getting this error: The type namespace.B was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

But XmlInclude is already included on top of class A .. should it be included elsewhere? :(
Jul 18 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jason Cartwright | last post by:
I have an abstract base class and two derived classes that I want to serialize and deserialize with schema validation. When I serialize instances of the derived classes the XmlSerializer adds the...
3
by: Carl Lindmark | last post by:
*Cross-posting from microsoft.public.dotnet.languages.csharp, since I believe the question is better suited in this XML group* Hello all, I'm having some problems understanding all the ins and...
4
by: pfrisbie | last post by:
I am developing a Web Services interface with C# and our partner is using Java (Axis 1.1). They require me to include xsi:types in the SOAP Messages I send them. For example: <Partner...
1
by: Ganesh Muthuvelu | last post by:
Hello, Is it possible to make the dataset give the "xsi:type" data as well?. I need result from the dataset.GetXML method something like this for the column "a": <a xsi:type="int">12</a> Is...
1
by: PeterW | last post by:
I have a bit of xml that I am trying to create an xsd schema from. A very simplified version is as follows: <?xml version="1.0" encoding="UTF-8"?> <centre...
0
by: tim.almond | last post by:
I have an arraylist with up to 4 different classes that can be contained. e.g.... <carpark> <car /> <truck /> <motorcycle /> <rv /> </carpark>
0
by: delirio | last post by:
Hi, I have an XML Schema containing inherited complex types, and xs:elements using @type of the top complex type, meaning, any child complex type can be an instance of that element by declaring...
0
by: =?Utf-8?B?U2hhbm5vbiBCYXJiZXI=?= | last post by:
I have created a schema to write out some configuration data, and the OutPort element uses an abstract complex type (it can be a Message, Discrete, Continuous, Array, etc...). I use the provided...
2
by: oh.i.love.spam | last post by:
This is just an example... I don't have the access/ability to upload the actual code. Here is the meat in the XML that is returned from the $client- <VesselConfigurations...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.