Permalink
Browse files

Do not import xs:any member as XmlElement[]. Create a wrapper class i…

…nstead.

Part of bugfix #670945.
  • Loading branch information...
1 parent e4816c5 commit e1f4f82a0a80b1e3d159785f50287f17860288b4 Atsushi Eno committed May 16, 2011
@@ -602,10 +602,6 @@ XmlTypeMapping ImportClassComplexType (XmlQualifiedName typeQName, XmlSchemaComp
// the class map is registered before parsing the children. We can't do the same
// with the array type because to register the array map we need the type of the array.
- Type anyType = GetAnyElementType (stype);
- if (anyType != null)
- return GetTypeMapping (TypeTranslator.GetTypeData(anyType));
-
if (CanBeArray (typeQName, stype))
{
TypeData typeData;
@@ -39,6 +39,7 @@
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
+using Microsoft.CSharp;
using NUnit.Framework;
@@ -1204,6 +1205,22 @@ public void ImportSimpleSchemaType ()
Assert.AreEqual ("b", tm.TypeName, "#2");
}
+ [Test]
+ public void ImportWildcardElementAsClass ()
+ {
+ var xss = new XmlSchemas ();
+ xss.Add (XmlSchema.Read (XmlReader.Create ("Test/XmlFiles/xsd/670945-1.xsd"), null));
+ xss.Add (XmlSchema.Read (XmlReader.Create ("Test/XmlFiles/xsd/670945-2.xsd"), null));
+ var imp = new XmlSchemaImporter (xss);
+ var xtm = imp.ImportSchemaType (new XmlQualifiedName ("SystemDateTime", "http://www.onvif.org/ver10/schema"));
+ var cns = new CodeNamespace ();
+ var exp = new XmlCodeExporter (cns);
+ exp.ExportTypeMapping (xtm);
+ var sw = new StringWriter ();
+ new CSharpCodeProvider ().GenerateCodeFromNamespace (cns, sw, null);
+ Assert.IsTrue (sw.ToString ().IndexOf ("class SystemDateTimeExtension") > 0, "#1");
+ }
+
XmlSchemaImporter CreateImporter (params string [] schemaXmlStrings)
{
XmlSchemas xss = new XmlSchemas ();
@@ -0,0 +1,22 @@
+ <xs:schema
+ targetNamespace="http://www.onvif.org/ver10/schema"
+ elementFormDefault="qualified"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tt="http://www.onvif.org/ver10/schema">
+
+ <xs:complexType name="SystemDateTime">
+ <xs:sequence>
+ <xs:element name="foobar" type="xs:string" minOccurs="0" />
+ <xs:element name="Extension" type="tt:SystemDateTimeExtension" minOccurs="0"/>
+ </xs:sequence>
+ <!-- xs:anyAttribute processContents="lax"/ -->
+ </xs:complexType>
+
+ <xs:complexType name="SystemDateTimeExtension">
+ <xs:sequence>
+ <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ </xs:schema>
+
@@ -0,0 +1,17 @@
+ <xs:schema targetNamespace="http://www.onvif.org/ver10/device/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" elementFormDefault="qualified"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="GetSystemDateAndTime">
+ <xs:complexType>
+ <xs:sequence/>
+
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="GetSystemDateAndTimeResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="SystemDateAndTime" type="tt:SystemDateTime" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:schema>
+

0 comments on commit e1f4f82

Please sign in to comment.