//
using System;
using System.Collections;
+using System.Collections.Generic;
using System.Xml;
using System.IO;
using System.Xml.Serialization;
// It is used by XmlSchemaCollection.Add() and XmlSchemaSet.Remove().
internal void CompileSubset (ValidationEventHandler handler, XmlSchemaSet col, XmlResolver resolver)
{
- Hashtable handledUris = new Hashtable ();
+ var handledUris = new List<CompiledSchemaMemo> ();
CompileSubset (handler, col, resolver, handledUris);
}
// It is used by XmlSchemaSet.Compile().
- internal void CompileSubset (ValidationEventHandler handler, XmlSchemaSet col, XmlResolver resolver, Hashtable handledUris)
+ internal void CompileSubset (ValidationEventHandler handler, XmlSchemaSet col, XmlResolver resolver, List<CompiledSchemaMemo> handledUris)
{
if (SourceUri != null && SourceUri.Length > 0) {
- if (handledUris.Contains (SourceUri))
+ // if it has line info and are the same as one of existing info, then skip it.
+ if (Contains (handledUris))
return;
- handledUris.Add (SourceUri, SourceUri);
+ handledUris.Add (new CompiledSchemaMemo () { SourceUri = this.SourceUri, LineNumber = this.LineNumber, LinePosition = this.LinePosition});
}
DoCompile (handler, handledUris, col, resolver);
}
+ bool Contains (List<CompiledSchemaMemo> handledUris)
+ {
+ foreach (var i in handledUris)
+ if (i.SourceUri.Equals (SourceUri) && i.LineNumber != 0 && i.LineNumber == LineNumber && i.LinePosition == LinePosition)
+ return true;
+ return false;
+ }
+
void SetParent ()
{
for (int i = 0; i < Items.Count; i++)
Includes [i].SetParent (this);
}
- void DoCompile (ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver)
+ void DoCompile (ValidationEventHandler handler, List<CompiledSchemaMemo> handledUris, XmlSchemaSet col, XmlResolver resolver)
{
SetParent ();
CompilationId = col.CompilationId;
#endif
}
- void ProcessExternal (ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaExternal ext, XmlSchemaSet col)
+ void ProcessExternal (ValidationEventHandler handler, List<CompiledSchemaMemo> handledUris, XmlResolver resolver, XmlSchemaExternal ext, XmlSchemaSet col)
{
if (ext == null) {
error (handler, String.Format ("Object of Type {0} is not valid in Includes Property of XmlSchema", ext.GetType().Name));
string url = null;
if (resolver != null) {
url = GetResolvedUri (resolver, ext.SchemaLocation);
- if (handledUris.Contains (url))
- // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
- return;
- handledUris.Add (url, url);
+ foreach (var i in handledUris)
+ if (i.SourceUri.Equals (url))
+ // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
+ return;
+ handledUris.Add (new CompiledSchemaMemo () { SourceUri = url });
try {
stream = resolver.GetEntity (new Uri (url), null, typeof (Stream)) as Stream;
} catch (Exception) {
}
- void AddExternalComponentsTo (XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaSet col)
+ void AddExternalComponentsTo (XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, List<CompiledSchemaMemo> handledUris, XmlResolver resolver, XmlSchemaSet col)
{
foreach (XmlSchemaExternal ext in s.Includes)
s.ProcessExternal (handler, handledUris, resolver, ext, col);
return new XmlSchemaSerializationWriter ();
}
}
+
+ class CompiledSchemaMemo
+ {
+ public string SourceUri;
+ public int LineNumber;
+ public int LinePosition;
+ }
}
internal ArrayList unhandledAttributeList ;
internal bool isCompiled = false;
internal int errorCount = 0;
- internal Guid CompilationId;
+ internal Guid compilation_id;
internal Guid ValidationId;
internal bool isRedefineChild;
internal bool isRedefinedComponent;
{
namespaces = new XmlSerializerNamespaces();
unhandledAttributeList = null;
- CompilationId = Guid.Empty;
+ compilation_id = Guid.Empty;
+ }
+
+ internal Guid CompilationId {
+ get { return compilation_id; }
+ set {
+ if (value.Equals (Guid.Empty))
+ throw new ArgumentException ("value must not be empty");
+ compilation_id = value;
+ }
}
[XmlIgnore]
var xsd = schemas.Add ("", XmlReader.Create (new StringReader (xsdraw)));
Assert.IsNull (xsd.TargetNamespace, "#1");
}
+
+ [Test] // part of bug #670945
+ public void TwoSchemasInSameDocumentUri ()
+ {
+ string xsd1 = @"
+ <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>";
+
+ string xsd2 = @"
+ <xs:schema
+ targetNamespace='http://www.onvif.org/ver10/device/wsdl'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'
+ xmlns:tt='http://www.onvif.org/ver10/schema'
+ xmlns:tds='http://www.onvif.org/ver10/device/wsdl'
+ elementFormDefault='qualified'>
+ <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>";
+
+ var xss = new XmlSchemaSet ();
+ var xs1 = XmlSchema.Read (new StringReader (xsd1), null);
+ xs1.SourceUri = "http://localhost:8080/dummy.wsdl";
+ xs1.LineNumber = 5;
+ xss.Add (xs1);
+ var xs2 = XmlSchema.Read (new StringReader (xsd2), null);
+ xs2.SourceUri = "http://localhost:8080/dummy.wsdl";
+ xs2.LineNumber = 50;
+ xss.Add (xs2);
+ xss.Compile ();
+ Assert.IsNotNull (xss.GlobalElements [new XmlQualifiedName ("GetSystemDateAndTimeResponse", "http://www.onvif.org/ver10/device/wsdl")], "#1");
+ }
}
}
#endif