Welcome to mirror list, hosted at ThFree Co, Russian Federation.

XsdValidatingReaderTests.cs « System.Xml « Test « System.XML « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8bbcf11706afb9a0939b1d0f078e2224fd2bb6be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
//
// MonoTests.System.Xml.XsdValidatingReaderTests.cs
//
// Author:
//	Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
//
// (C)2003 Atsushi Enomoto
// (C)2005-2007 Novell, Inc.
//
using System;
using System.IO;
using System.Net;
using System.Xml;
using System.Xml.Schema;
using NUnit.Framework;

namespace MonoTests.System.Xml
{
	[TestFixture]
	public class XsdValidatingReaderTests
	{
		public XsdValidatingReaderTests ()
		{
		}

		XmlReader xtr;
		XmlValidatingReader xvr;

		private XmlValidatingReader PrepareXmlReader (string xml)
		{
			XmlReader reader = new XmlTextReader (xml, XmlNodeType.Document, null);
//			XmlDocument doc = new XmlDocument ();
//			doc.LoadXml (xml);
//			XmlReader reader = new XmlNodeReader (doc);

			return new XmlValidatingReader (reader);
		}

		[Test]
		public void TestEmptySchema ()
		{
			string xml = "<root/>";
			xvr = PrepareXmlReader (xml);
			xvr.ValidationType = ValidationType.Schema;
			xvr.Read ();	// Is is missing schema component.
		}

		[Test]
		public void TestSimpleValidation ()
		{
			string xml = "<root/>";
			xvr = PrepareXmlReader (xml);
			Assert.AreEqual (ValidationType.Auto, xvr.ValidationType);
			XmlSchema schema = new XmlSchema ();
			XmlSchemaElement elem = new XmlSchemaElement ();
			elem.Name = "root";
			schema.Items.Add (elem);
			xvr.Schemas.Add (schema);
			xvr.Read ();	// root
			Assert.AreEqual (ValidationType.Auto, xvr.ValidationType);
			xvr.Read ();	// EOF

			xml = "<hoge/>";
			xvr = PrepareXmlReader (xml);
			xvr.Schemas.Add (schema);
			try {
				xvr.Read ();
				Assert.Fail ("element mismatch is incorrectly allowed");
			} catch (XmlSchemaException) {
			}

			xml = "<hoge xmlns='urn:foo' />";
			xvr = PrepareXmlReader (xml);
			xvr.Schemas.Add (schema);
			try {
				xvr.Read ();
				Assert.Fail ("Element in different namespace is incorrectly allowed.");
			} catch (XmlSchemaException) {
			}
		}

		[Test]
		public void TestReadTypedValueSimple ()
		{
			string xml = "<root>12</root>";
			XmlSchema schema = new XmlSchema ();
			XmlSchemaElement elem = new XmlSchemaElement ();
			elem.Name = "root";
			elem.SchemaTypeName = new XmlQualifiedName ("integer", XmlSchema.Namespace);
			schema.Items.Add (elem);

			// Lap 1:
			
			xvr = PrepareXmlReader (xml);
			xvr.Schemas.Add (schema);
			// Read directly from root.
			object o = xvr.ReadTypedValue ();
			Assert.AreEqual (ReadState.Initial, xvr.ReadState);
			Assert.IsNull (o);

			xvr.Read ();	// element root
			Assert.AreEqual (XmlNodeType.Element, xvr.NodeType);
			Assert.IsNotNull (xvr.SchemaType);
			Assert.IsTrue (xvr.SchemaType is XmlSchemaDatatype);
			o = xvr.ReadTypedValue ();	// read "12"
			Assert.AreEqual (XmlNodeType.EndElement, xvr.NodeType);
			Assert.IsNotNull (o);
			Assert.AreEqual (typeof (decimal), o.GetType ());
			decimal n = (decimal) o;
			Assert.AreEqual (12, n);
			Assert.IsTrue (!xvr.EOF);
			Assert.AreEqual ("root", xvr.Name);
			Assert.IsNull (xvr.SchemaType);	// EndElement's type

			// Lap 2:

			xvr = PrepareXmlReader (xml);
			xvr.Schemas.Add (schema);
			xvr.Read ();	// root
			XmlSchemaDatatype dt = xvr.SchemaType as XmlSchemaDatatype;
			Assert.IsNotNull (dt);
			Assert.AreEqual (typeof (decimal), dt.ValueType);
			Assert.AreEqual (XmlTokenizedType.None, dt.TokenizedType);
			xvr.Read ();	// text "12"
			Assert.IsNull (xvr.SchemaType);
			o = xvr.ReadTypedValue ();
			// ReadTypedValue is different from ReadString().
			Assert.IsNull (o);
		}

		[Test]
		[Ignore ("XML Schema validator should not be available for validating non namespace-aware XmlReader that handled colon as a name character")]
		public void TestNamespacesFalse ()
		{
			// This tests if Namespaces=false is specified, then
			// the reader's NamespaceURI should be always string.Empty and
			// validation should be done against such schema that has target ns as "".
			string xml = "<x:root xmlns:x='urn:foo' />";
			xvr = PrepareXmlReader (xml);
			xvr.Namespaces = false;
			Assert.AreEqual (ValidationType.Auto, xvr.ValidationType);
			XmlSchema schema = new XmlSchema ();
			schema.TargetNamespace = "urn:foo";
			XmlSchemaElement elem = new XmlSchemaElement ();
			elem.Name = "root";
			schema.Items.Add (elem);
			xvr.Schemas.Add (schema);
			xvr.Read ();	// root
			Assert.IsTrue (!xvr.Namespaces);
			Assert.AreEqual ("x:root", xvr.Name);
			// LocalName may contain colons.
			Assert.AreEqual ("x:root", xvr.LocalName);
			// NamespaceURI is not supplied.
			Assert.AreEqual ("", xvr.NamespaceURI);
		}

		[Test]
		public void TestReadTypedAttributeValue ()
		{
			string xml = "<root attr='12'></root>";
			XmlSchema schema = new XmlSchema ();
			XmlSchemaElement elem = new XmlSchemaElement ();
			elem.Name = "root";
			XmlSchemaComplexType ct = new XmlSchemaComplexType ();
			XmlSchemaAttribute attr = new XmlSchemaAttribute ();
			attr.Name = "attr";
			attr.SchemaTypeName = new XmlQualifiedName ("int", XmlSchema.Namespace);
			ct.Attributes.Add (attr);
			elem.SchemaType = ct;
			schema.Items.Add (elem);

			xvr = PrepareXmlReader (xml);
			xvr.Schemas.Add (schema);
			xvr.Read ();
			Assert.AreEqual ("root", xvr.Name);
			Assert.IsTrue (xvr.MoveToNextAttribute ());	// attr
			Assert.AreEqual ("attr", xvr.Name);
			XmlSchemaDatatype dt = xvr.SchemaType as XmlSchemaDatatype;
			Assert.IsNotNull (dt);
			Assert.AreEqual (typeof (int), dt.ValueType);
			Assert.AreEqual (XmlTokenizedType.None, dt.TokenizedType);
			object o = xvr.ReadTypedValue ();
			Assert.AreEqual (XmlNodeType.Attribute, xvr.NodeType);
			Assert.AreEqual (typeof (int), o.GetType ());
			int n = (int) o;
			Assert.AreEqual (12, n);
			Assert.IsTrue (xvr.ReadAttributeValue ());	// can read = seems not proceed.
		}

		[Test]
		public void DuplicateSchemaAssignment ()
		{
			string xml = @"<data
			xmlns='http://www.test.com/schemas/'
			xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
			xsi:schemaLocation='http://www.test.com/schemas/ /home/user/schema.xsd' />";
			string xsd = @"<xs:schema
			targetNamespace='http://www.test.com/schemas/'
			xmlns:xs='http://www.w3.org/2001/XMLSchema'
			xmlns='http://www.test.com/schemas/' >
		        <xs:element name='data' /></xs:schema>";

			string xmlns = "http://www.test.com/schemas/";

			XmlValidatingReader xvr = new XmlValidatingReader (
				xml, XmlNodeType.Document, null);
			XmlSchemaCollection schemas = new XmlSchemaCollection ();
			schemas.Add (XmlSchema.Read (new XmlTextReader (
				xsd, XmlNodeType.Document, null), null));
			xvr.Schemas.Add (schemas);
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test] // bug #76234
		public void DTDValidatorNamespaceHandling ()
		{
			string xml = "<xml xmlns='urn:a'> <foo> <a:bar xmlns='urn:b' xmlns:a='urn:a' /> <bug /> </foo> </xml>";
			XmlValidatingReader vr = new XmlValidatingReader (
				xml, XmlNodeType.Document, null);
			vr.Read ();
			vr.Read (); // whitespace
			Assert.AreEqual (String.Empty, vr.NamespaceURI, "#1");
			vr.Read (); // foo
			Assert.AreEqual ("urn:a", vr.NamespaceURI, "#2");
			vr.Read (); // whitespace
			vr.Read (); // a:bar
			Assert.AreEqual ("urn:a", vr.NamespaceURI, "#3");
			vr.Read (); // whitespace
			vr.Read (); // bug
			Assert.AreEqual ("urn:a", vr.NamespaceURI, "#4");
		}

		[Test]
		public void MultipleSchemaInSchemaLocation ()
		{
			XmlTextReader xtr = new XmlTextReader ("Test/XmlFiles/xsd/multi-schemaLocation.xml");
			XmlValidatingReader vr = new XmlValidatingReader (xtr);
			while (!vr.EOF)
				vr.Read ();
		}

		[Test]
		public void ReadTypedValueSimpleTypeRestriction ()
		{
			string xml = "<root>xx</root><!-- after -->";
			string xsd = @"
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
  <xs:element name='root'>
    <xs:simpleType>
      <xs:restriction base='xs:string'>
        <xs:minLength value='2' />
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>";
			XmlTextReader xir = 
				new XmlTextReader (xml, XmlNodeType.Document, null);
			XmlTextReader xsr =
				new XmlTextReader (xsd, XmlNodeType.Document, null);
			XmlValidatingReader vr = new XmlValidatingReader (xir);
			vr.Schemas.Add (XmlSchema.Read (xsr, null));
			vr.Read (); // root
			Assert.AreEqual ("xx", vr.ReadTypedValue ());
			Assert.AreEqual (XmlNodeType.EndElement, vr.NodeType);
		}

		// If we normalize string before validating with facets,
		// this test will fail. It will also fail if ReadTypedValue()
		// ignores whitespace nodes.
		[Test]
		public void ReadTypedValueWhitespaces ()
		{
			string xml = "<root>  </root><!-- after -->";
			string xsd = @"
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
  <xs:element name='root'>
    <xs:simpleType>
      <xs:restriction base='xs:string'>
        <xs:minLength value='2' />
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>";
			XmlTextReader xir = 
				new XmlTextReader (xml, XmlNodeType.Document, null);
			XmlTextReader xsr =
				new XmlTextReader (xsd, XmlNodeType.Document, null);
			XmlValidatingReader vr = new XmlValidatingReader (xir);
			vr.Schemas.Add (XmlSchema.Read (xsr, null));
			vr.Read (); // root
			Assert.AreEqual ("  ", vr.ReadTypedValue ());
			Assert.AreEqual (XmlNodeType.EndElement, vr.NodeType);
		}

		[Test] // bug #77241
		public void EmptyContentAllowWhitespace ()
		{
			string doc = @"
<root>
        <!-- some comment -->
        <child/>
</root>
";
			string schema = @"
<xsd:schema xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
    <xsd:element name=""root"">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name=""child"" type=""xsd:string"" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>
";
			XmlValidatingReader reader = new XmlValidatingReader (
				new XmlTextReader (new StringReader (doc)));
			reader.Schemas.Add (null,
				new XmlTextReader (new StringReader (schema)));
			while (reader.Read ())
				;
		}

		[Test] // bug #79650
		// LAMESPEC: .NET does not throw XmlSchemaValidationException
		[ExpectedException (typeof (XmlSchemaException))]
		public void EnumerationFacetOnAttribute ()
		{
			string xml = "<test mode='NOT AN ENUMERATION VALUE' />";
			XmlSchema schema = XmlSchema.Read (new XmlTextReader ("Test/XmlFiles/xsd/79650.xsd"), null);
			XmlValidatingReader xvr = new XmlValidatingReader (xml, XmlNodeType.Document, null);
			xvr.ValidationType = ValidationType.Schema;
			xvr.Schemas.Add (schema);
			while (!xvr.EOF)
				xvr.Read ();
		}

		class XmlErrorResolver : XmlResolver
		{
			public override ICredentials Credentials {
				set { }
			}

			public override object GetEntity (Uri uri, string role, Type type)
			{
				throw new Exception ();
			}
		}

		[Test] // bug #79924
		public void ValidationTypeNoneIgnoreSchemaLocations ()
		{
			string xml = "<project xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='nosuchschema.xsd'/>";
			XmlValidatingReader vr = new XmlValidatingReader (
				new XmlTextReader (new StringReader (xml)));
			vr.ValidationType = ValidationType.None;
			vr.XmlResolver = new XmlErrorResolver ();
			while (!vr.EOF)
				vr.Read ();
		}

		[Test] // bug #336625
		public void ValidationTypeNoneIgnoreLocatedSchemaErrors ()
		{
			string xml = "<test xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='Test/XmlFiles/xsd/336625.xsd'/>";
			XmlValidatingReader vr = new XmlValidatingReader (
				new XmlTextReader (new StringReader (xml)));
			vr.ValidationType = ValidationType.None;
			while (!vr.EOF)
				vr.Read ();
		}

		[Test]
		public void Bug81360 ()
		{
			string schemaFile = "Test/XmlFiles/xsd/81360.xsd";
			XmlTextReader treader = new XmlTextReader (schemaFile);
			XmlSchema sc = XmlSchema.Read (treader, null);
			sc.Compile (null);
			string xml = @"<body xmlns='" + sc.TargetNamespace + "'><div></div></body>";
			XmlTextReader reader = new XmlTextReader (new StringReader (xml));
			XmlValidatingReader validator = new XmlValidatingReader (reader);
			validator.Schemas.Add (sc);
			validator.ValidationType = ValidationType.Schema;
			while (!validator.EOF)
				validator.Read ();
		}

		[Test]
		public void Bug81460 ()
		{
			string xsd = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'><xs:element name='foo'><xs:complexType><xs:attribute name='a' default='x' /></xs:complexType></xs:element></xs:schema>";
			string xml = "<foo/>";
			XmlReaderSettings s = new XmlReaderSettings ();
			s.ValidationType = ValidationType.Schema;
			s.Schemas.Add (XmlSchema.Read (new StringReader (xsd), null));
			XmlReader r = XmlReader.Create (new StringReader (xml), s);
			r.Read ();
			r.MoveToFirstAttribute (); // default attribute
			Assert.AreEqual (String.Empty, r.Prefix);
		}

		[Test]
		// annoyance
		[ExpectedException (typeof (XmlSchemaValidationException))]
		public void Bug82099 ()
		{
			string xsd = @"
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
  <xsd:element name='Customer' type='CustomerType' />
  <xsd:complexType name='CustomerType'>
    <xsd:attribute name='name' type='xsd:string' />
  </xsd:complexType>
</xsd:schema>";
			XmlSchema schema = XmlSchema.Read (new StringReader (xsd), null);

			string xml = "<Customer name='Bob'> </Customer>";

			XmlReaderSettings settings = new XmlReaderSettings ();
			settings.Schemas.Add (schema);
			settings.ValidationType = ValidationType.Schema;

			XmlReader reader = XmlReader.Create (new StringReader (xml), settings);
			
			reader.Read ();
			reader.Read ();
			reader.Read ();
		}

		[Test]
		public void Bug82010 ()
		{
			string xmlfile = "Test/XmlFiles/xsd/82010.xml";
			string xsdfile = "Test/XmlFiles/xsd/82010.xsd";
			XmlTextReader xr = null, xr2 = null;
			try {
				xr = new XmlTextReader (xsdfile);
				xr2 = new XmlTextReader (xmlfile);
				XmlValidatingReader xvr = new XmlValidatingReader (xr2);
				xvr.Schemas.Add (XmlSchema.Read (xr, null));
				while (!xvr.EOF)
					xvr.Read ();
			} finally {
				if (xr2 != null)
					xr2.Close ();
				if (xr != null)
					xr.Close ();
			}
		}

		[Test]
		public void Bug376395 ()
		{
			string xmlfile = "Test/XmlFiles/xsd/376395.xml";
			string xsdfile = "Test/XmlFiles/xsd/376395.xsd";
			XmlTextReader xr = null, xr2 = null;
			try {
				xr = new XmlTextReader (xsdfile);
				xr2 = new XmlTextReader (xmlfile);
				XmlValidatingReader xvr = new XmlValidatingReader (xr2);
				xvr.Schemas.Add (XmlSchema.Read (xr, null));
				while (!xvr.EOF)
					xvr.Read ();
			} finally {
				if (xr2 != null)
					xr2.Close ();
				if (xr != null)
					xr.Close ();
			}
		}

		[Test]
		public void ValidateMixedInsideXsdAny ()
		{
			string xml = @"<root xmlns='urn:foo'>
  <X><Z>text</Z></X>
  <Y><X><Z>text</Z></X></Y>
</root>";
			string xsd = @"
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
  targetNamespace='urn:foo' xmlns='urn:foo'>
    <xs:complexType name='root-type'>
      <xs:sequence><xs:element ref='X' /><xs:element ref='Y' /></xs:sequence>
    </xs:complexType>
    <xs:complexType name='X-type'>
      <xs:choice minOccurs='1' maxOccurs='unbounded'>
        <xs:any processContents='skip'/>
      </xs:choice>
    </xs:complexType>
    <xs:complexType name='Y-type'>
      <xs:sequence><xs:element ref='X' /></xs:sequence>
    </xs:complexType>
  <xs:element name='root' type='root-type' />
  <xs:element name='X' type='X-type' />
  <xs:element name='Y' type='Y-type' />
</xs:schema>";
			XmlTextReader xtr = new XmlTextReader (new StringReader (xml));
			XmlValidatingReader xvr = new XmlValidatingReader (xtr);
			XmlReader xsr = new XmlTextReader (new StringReader (xsd));
			xvr.Schemas.Add (XmlSchema.Read (xsr, null));
			while (!xvr.EOF)
				xvr.Read ();
			xtr = new XmlTextReader (new StringReader (xml));
			xsr = new XmlTextReader (new StringReader (xsd));
			var s = new XmlReaderSettings ();
			s.Schemas.Add (XmlSchema.Read (xsr, null));
			s.ValidationType = ValidationType.Schema;
			XmlReader xvr2 = XmlReader.Create (xtr, s);
			while (!xvr2.EOF)
				xvr2.Read ();
		}

		[Test]
		public void WhitespaceAndElementOnly ()
		{
			string xsd = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
  <xs:element name='element_list'>
    <xs:complexType>
      <xs:sequence>
        <xs:element name='element' maxOccurs='unbounded' />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>";
			string xml = @"<element_list>
    <!-- blah blah blah -->
    <element />

    <!-- blah blah -->
    <element />
</element_list>";
			RunValidation (xml, xsd);
		}

		[Test]
		[ExpectedException (typeof (XmlSchemaValidationException))]
		public void EnumerationFacet ()
		{
			// bug #339934
			string xsd = @"<xs:schema id='schema' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
    <xs:simpleType name='ModeType'>
        <xs:restriction base='xs:string'>
            <xs:enumeration value='on' />
            <xs:enumeration value='off' />
        </xs:restriction>
    </xs:simpleType>
    <xs:element name='test'>
        <xs:complexType>
            <xs:sequence/>
            <xs:attribute name='mode' type='ModeType' use='required' />
        </xs:complexType>
    </xs:element>
</xs:schema>";
			string xml = @"<test mode='out of scope'></test>";

			RunValidation (xml, xsd);
		}
		
		[Test]
		public void Bug501763 ()
		{
			string xsd1 = @"
			<xs:schema id='foo1'
				targetNamespace='foo1'
				elementFormDefault='qualified'
				xmlns='foo1'			  
				xmlns:xs='http://www.w3.org/2001/XMLSchema'
				xmlns:f2='foo2'>

				<xs:import namespace='foo2' />
				<xs:element name='Foo1Element' type='f2:Foo2ExtendedType'/>	
			</xs:schema>";

			string xsd2 = @"
			<xs:schema id='foo2'
				targetNamespace='foo2'
				elementFormDefault='qualified'
				xmlns='foo2'    
				xmlns:xs='http://www.w3.org/2001/XMLSchema' >

				<xs:element name='Foo2Element' type='Foo2Type' />
	
				<xs:complexType name='Foo2Type'>
					<xs:attribute name='foo2Attr' type='xs:string' use='required'/>
				</xs:complexType>
	
				<xs:complexType name='Foo2ExtendedType'>
					<xs:complexContent>
						<xs:extension base='Foo2Type'>
							<xs:attribute name='foo2ExtAttr' type='xs:string' use='required'/>
						</xs:extension>
					</xs:complexContent>
				</xs:complexType>
			</xs:schema>";

			
			XmlDocument doc = new XmlDocument ();
			
			XmlSchema schema1 = XmlSchema.Read (XmlReader.Create (new StringReader (xsd1)), null);
			XmlSchema schema2 = XmlSchema.Read (XmlReader.Create (new StringReader (xsd2)), null);
			
			doc.LoadXml (@"
				<Foo2Element
					foo2Attr='dummyvalue1'
					xmlns='foo2'
				/>");
			doc.Schemas.Add (schema2);
			doc.Validate (null);
			
			doc = new XmlDocument();
			doc.LoadXml(@"
				<Foo1Element
					foo2Attr='dummyvalue1'
					foo2ExtAttr='dummyvalue2'
					xmlns='foo1'
				/>");
			doc.Schemas.Add (schema2);
			doc.Schemas.Add (schema1);
			doc.Validate (null);
		}
		
		void RunValidation (string xml, string xsd)
		{
			XmlReaderSettings s = new XmlReaderSettings ();
			s.ValidationType = ValidationType.Schema;
			s.Schemas.Add (XmlSchema.Read (XmlReader.Create (new StringReader (xsd)), null));

			XmlReader r = XmlReader.Create (new StringReader (xml), s);
			while (!r.EOF)
				r.Read ();
		}
	}
}