473,320 Members | 1,746 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,320 software developers and data experts.

XML Inheritance

I posted this message yesterday on a different group which may have been the
wrong group, so I am not cross posting on purpose.

Hi,

I have a question regarding how the .Net framework interprets schema
definitions based on existing types.

I have (for the purposes of demonstration) a very simple types schema which
contains some PersonName (T_PERSONNAME) and Address (T_ADDRESS) details as
below.

<?xml version="1.0" encoding="utf-16" ?>

- <xs:schema xmlns=http://com.test.schemas.BaseTypes
xmlns:b="http://schemas.microsoft.com/BizTalk/2003"
targetNamespace=http://com.test.schemas.BaseTypes
xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xs:element name="BaseTypes">
- <xs:complexType>
- <xs:sequence>
<xs:element name="PersonName" type="T_PERSONNAME" />
<xs:element name="AddressDetails" type="T_ADDRESS" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:complexType name="T_PERSONNAME">
- <xs:sequence>
<xs:element name="Forename" type="xs:string" />
<xs:element name="Surname" type="xs:string" />
<xs:element name="MiddleName" type="xs:string" />
</xs:sequence>
</xs:complexType>
- <xs:complexType name="T_ADDRESS">
- <xs:sequence>
<xs:element name="Address1" type="xs:string" />
<xs:element name="Address2" type="xs:string" />
<xs:element name="Address3" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>

I use these types to define a "Person" with some extensions.

<?xml version="1.0" encoding="utf-16" ?>
- <xs:schema xmlns:typ=http://com.test.schemas.BaseTypes
xmlns:b="http://schemas.microsoft.com/BizTalk/2003"
xmlns=http://com.test.schemas.Person
targetNamespace=http://com.test.schemas.Person
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation=".\basetypes.xsd"
namespace=http://com.test.schemas.BaseTypes />
- <xs:annotation>
- <xs:appinfo>
- <b:references>
<b:reference targetNamespace=http://com.test.schemas.BaseTypes />
</b:references>
</xs:appinfo>
</xs:annotation>
- <xs:element name="Person">
- <xs:complexType>
- <xs:sequence>
<xs:element name="id" type="xs:string" />
- <xs:element name="PersonName">
- <xs:complexType>
- <xs:complexContent mixed="false">
- <xs:extension base="typ:T_PERSONNAME">
- <xs:sequence>
- <xs:element name="FathersName">
- <xs:complexType>
- <xs:sequence>
<xs:element name="Forename" type="xs:string" />
<xs:element name="Surname" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Alias" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

I use the xsdobjectgen .Net add-in tool to create data structures to support
these schemas. These (to me) look fine

// Copyright 2004, Microsoft Corporation

// Sample Code - Use restricted to terms of use defined in the accompanying
license agreement (EULA.doc)

//--------------------------------------------------------------

// Autogenerated by XSDObjectGen version 1.4.2.1

// Schema file: Person.xsd

// Creation Date: 21/03/2006 15:14:03

//--------------------------------------------------------------

using System;

using System.Xml.Serialization;

using System.Collections;

using System.Xml.Schema;

using System.ComponentModel;

namespace http___com_test_schemas_BaseTypes

{

public struct Declarations

{

public const string SchemaVersion = "http://com.test.schemas.BaseTypes";

}



[XmlType(TypeName="T_ADDRESS"),Serializable]

[EditorBrowsable(EditorBrowsableState.Advanced)]

public class T_ADDRESS

{

[XmlElement(ElementName="Address1",IsNullable=false ,DataType="string")]

[EditorBrowsable(EditorBrowsableState.Advanced)]

public string __Address1;
[XmlIgnore]

public string Address1

{

get { return __Address1; }

set { __Address1 = value; }

}

[XmlElement(ElementName="Address2",IsNullable=false ,DataType="string")]

[EditorBrowsable(EditorBrowsableState.Advanced)]

public string __Address2;
[XmlIgnore]

public string Address2

{

get { return __Address2; }

set { __Address2 = value; }

}

[XmlElement(ElementName="Address3",IsNullable=false ,DataType="string")]

[EditorBrowsable(EditorBrowsableState.Advanced)]

public string __Address3;
[XmlIgnore]

public string Address3

{

get { return __Address3; }

set { __Address3 = value; }

}

public T_ADDRESS()

{

}

}

[XmlType(TypeName="T_PERSONNAME"),Serializable]

[EditorBrowsable(EditorBrowsableState.Advanced)]

public class T_PERSONNAME

{

[XmlElement(ElementName="Forename",IsNullable=false ,DataType="string")]

[EditorBrowsable(EditorBrowsableState.Advanced)]

public string __Forename;
[XmlIgnore]

public string Forename

{

get { return __Forename; }

set { __Forename = value; }

}

[XmlElement(ElementName="Surname",IsNullable=false, DataType="string")]

[EditorBrowsable(EditorBrowsableState.Advanced)]

public string __Surname;
[XmlIgnore]

public string Surname

{

get { return __Surname; }

set { __Surname = value; }

}

[XmlElement(ElementName="MiddleName",IsNullable=fal se,DataType="string")]

[EditorBrowsable(EditorBrowsableState.Advanced)]

public string __MiddleName;
[XmlIgnore]

public string MiddleName

{

get { return __MiddleName; }

set { __MiddleName = value; }

}

public T_PERSONNAME()

{

}

}

[XmlRoot(ElementName="BaseTypes",Namespace=Declarat ions.SchemaVersion,IsNullable=false),Serializable]

public class BaseTypes

{

[XmlElement(Type=typeof(http___com_test_schemas_Bas eTypes.T_PERSONNAME),ElementName="PersonName",IsNu llable=false)]

[EditorBrowsable(EditorBrowsableState.Advanced)]

public http___com_test_schemas_BaseTypes.T_PERSONNAME __PersonName;
[XmlIgnore]

public http___com_test_schemas_BaseTypes.T_PERSONNAME PersonName

{

get

{

if (__PersonName == null) __PersonName = new
http___com_test_schemas_BaseTypes.T_PERSONNAME();

return __PersonName;

}

set {__PersonName = value;}

}

[XmlElement(Type=typeof(http___com_test_schemas_Bas eTypes.T_ADDRESS),ElementName="AddressDetails",IsN ullable=false)]

[EditorBrowsable(EditorBrowsableState.Advanced)]

public http___com_test_schemas_BaseTypes.T_ADDRESS __AddressDetails;
[XmlIgnore]

public http___com_test_schemas_BaseTypes.T_ADDRESS AddressDetails

{

get

{

if (__AddressDetails == null) __AddressDetails = new
http___com_test_schemas_BaseTypes.T_ADDRESS();

return __AddressDetails;

}

set {__AddressDetails = value;}

}

public BaseTypes()

{

}

}

}


// Copyright 2004, Microsoft Corporation
// Sample Code - Use restricted to terms of use defined in the accompanying
license agreement (EULA.doc)

//--------------------------------------------------------------
// Autogenerated by XSDObjectGen version 1.4.2.1
// Schema file: Person.xsd
// Creation Date: 21/03/2006 15:14:02
//--------------------------------------------------------------

using System;
using System.Xml.Serialization;
using System.Collections;
using System.Xml.Schema;
using System.ComponentModel;

namespace http_com_test_schemas_Person
{

public struct Declarations
{
public const string SchemaVersion = "http://com.test.schemas.Person";
}

[XmlRoot(ElementName="Person",Namespace=Declaration s.SchemaVersion,IsNullable=false),Serializable]
public class Person
{

[XmlElement(ElementName="id",IsNullable=false,DataT ype="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __id;

[XmlIgnore]
public string id
{
get { return __id; }
set { __id = value; }
}
[XmlElement(Type=typeof(PersonName),ElementName="Pe rsonName",IsNullable=false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public PersonName __PersonName;

[XmlIgnore]
public PersonName PersonName
{
get
{
if (__PersonName == null) __PersonName = new PersonName();
return __PersonName;
}
set {__PersonName = value;}
}

public Person()
{
}
}
[XmlType(TypeName="PersonName"),Serializable]
public class PersonName : http___com_test_schemas_BaseTypes.T_PERSONNAME
{
[XmlElement(Type=typeof(FathersName),ElementName="F athersName",IsNullable=false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public FathersName __FathersName;

[XmlIgnore]
public FathersName FathersName
{
get
{
if (__FathersName == null) __FathersName = new FathersName();
return __FathersName;
}
set {__FathersName = value;}
}

[XmlElement(ElementName="Alias",IsNullable=false,Da taType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Alias;

[XmlIgnore]
public string Alias
{
get { return __Alias; }
set { __Alias = value; }
}

public PersonName() : base()
{
}
}
[XmlType(TypeName="FathersName"),Serializable]
public class FathersName
{

[XmlElement(ElementName="Forename",IsNullable=false ,DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Forename;

[XmlIgnore]
public string Forename
{
get { return __Forename; }
set { __Forename = value; }
}

[XmlElement(ElementName="Surname",IsNullable=false, DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Surname;

[XmlIgnore]
public string Surname
{
get { return __Surname; }
set { __Surname = value; }
}

public FathersName()
{
}
}
}


My problem is that when I actually browse the web service I do not see any
evidence of the PersonName base type which is inherited in Person.cs the line
in the class is

[XmlType(TypeName="PersonName"),Serializable]
public class PersonName : http___com_test_schemas_BaseTypes.T_PERSONNAME
The browser output is

TestInheritance

Test
The test form is only available for methods with primitive types or arrays
of primitive types as parameters.
SOAP
The following is a sample SOAP request and response. The placeholders shown
need to be replaced with actual values.

POST /XMLInheritanceSample/Service1.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/TestInheritance"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TestInheritance xmlns="http://tempuri.org/">
<Person xmlns="http://com.test.schemas.Person">
<id>string</id>
<PersonName>
<FathersName>
<Forename>string</Forename>
<Surname>string</Surname>
</FathersName>
<Alias>string</Alias>
</PersonName>
</Person>
</TestInheritance>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TestInheritanceResponse xmlns="http://tempuri.org/">
<TestInheritanceResult>string</TestInheritanceResult>
</TestInheritanceResponse>
</soap:Body>
</soap:Envelope>
Is there a reason for this?

BTW I can see the T_PERSONNAME defined in the service descripton.

Thanks in advance.


Mar 22 '06 #1
0 1873

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
4
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that...
5
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
10
by: davidrubin | last post by:
Structural inheritance (inheriting implementation) is equivalent to composition in that a particular method must either call 'Base::foo' or invoke 'base.foo'. Apparantly, The Literature tells us to...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
6
by: Bart Simpson | last post by:
I remember reading on parashift recently, that "Composition is for code reuse, inheritance is for flexibility" see (http://www.parashift.com/c++-faq-lite/smalltalk.html#faq-30.4) This confused...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.