cjard
Well-known member
- Joined
- Apr 25, 2006
- Messages
- 7,081
- Programming Experience
- 10+
Hi all
I have an XSD that has a relatively simple structure:
two complex types
the root element contains a choice of one of two elements, both of which are the parent complex type, but with different names on the parent and child complex type
Note that the details are the same type.
Yep; it's a bit screwy in that, save for the names in the xml, these types are the same all through:
In trying to get one xsd to validate both these kinds of XML, i've made it a Choice between either resultAs or a resultB and renamed the child elements but kept their type.
Here's the XSD:
When xsd produces the classes, it makes:
[XmlType(Anonymous, Namespace ="whatever")]
rootE
[XmlType(Anonymous)]
rootEresultA
[XmlType(Anonymous)]
rootEresultB
There are no namespace declares on the resultA or B classes. When serialized they look like:
...<resultA xmlns="">...
...<resultB xmlns="">...
Why were no namespaces generated on the class code, or, why does XmlSerilaizer not mark them as being part of the namespace of the root element (that is their parent)?
On an unrelated note; it's clear to me that one inheritance hierarchy could take over this and reduce the amount of work I have to do treating everything as separate objects. Problem I've found is that asmx won't generate a very detailed WSDL if inherited classes are used; it stops at the point where the inheritance tree starts and doesnt bother to describe the classes below. Any way I can rewrite my xsd to better represent this xml, perhaps with base types, so I don't have to have multiple types in my program, that are essentually the same code?
I have an XSD that has a relatively simple structure:
two complex types
the root element contains a choice of one of two elements, both of which are the parent complex type, but with different names on the parent and child complex type
VB.NET:
rootE
+resultA (parentComplexType1)
+detailA (childComplexType)
+resultB (parentComplexType2)
+detailB (childComplexType)
Note that the details are the same type.
Yep; it's a bit screwy in that, save for the names in the xml, these types are the same all through:
VB.NET:
<rootE>
<resultA>
<detailA detail="hello world"/>
</resultA>
<resultA>
<detailA detail="hello world2"/>
</resultA>
</rootE>
<rootE>
<resultB>
<detailB detail="hello world"/>
</resultB>
</rootE>
Here's the XSD:
VB.NET:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="whatever" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns="whatever" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:element name="rootE">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element name="resultA">
<xs:complexType>
<xs:sequence>
<xs:element name="detailA" type="ns:complexType">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="resultB">
<xs:complexType>
<xs:sequence>
<xs:element name="detailB" maxOccurs="1" minOccurs="1" type="ns:complexType">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="complexType">
<xs:attribute name="detail" type="xs:string" />
</xs:complexType>
</xs:schema>
When xsd produces the classes, it makes:
[XmlType(Anonymous, Namespace ="whatever")]
rootE
[XmlType(Anonymous)]
rootEresultA
[XmlType(Anonymous)]
rootEresultB
There are no namespace declares on the resultA or B classes. When serialized they look like:
...<resultA xmlns="">...
...<resultB xmlns="">...
Why were no namespaces generated on the class code, or, why does XmlSerilaizer not mark them as being part of the namespace of the root element (that is their parent)?
On an unrelated note; it's clear to me that one inheritance hierarchy could take over this and reduce the amount of work I have to do treating everything as separate objects. Problem I've found is that asmx won't generate a very detailed WSDL if inherited classes are used; it stops at the point where the inheritance tree starts and doesnt bother to describe the classes below. Any way I can rewrite my xsd to better represent this xml, perhaps with base types, so I don't have to have multiple types in my program, that are essentually the same code?