blob: 70e2c2f6b462a98205c7950ed43fdce2b394c02e (
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
|
//
// RelaxngDatatypeProviderTest.cs
//
// Authors:
// Atsushi Enomoto <atsushi@ximian.com>
//
using System;
using System.IO;
using System.Xml;
using Commons.Xml.Relaxng;
using Commons.Xml.Relaxng.XmlSchema;
using NUnit.Framework;
using MonoTests.Helpers;
namespace MonoTests.Commons.Xml.Relaxng
{
[TestFixture]
public class RelaxngDatatypeProviderTests
{
[Test]
public void CustomTypeProvider ()
{
var datatypeLibrary = SetupMyDataProvider ();
XmlDocument xml = new XmlDocument ();
xml.LoadXml ("<root> <v1>mytype</v1> <v2>1</v2> </root>");
XmlDocument schemaXml = ReadDoc (TestResourceHelper.GetFullPathOfResource ("Test/XmlFiles/463264.rng"));
XmlReader reader = new RelaxngValidatingReader (new XmlNodeReader (xml), new XmlNodeReader (schemaXml), datatypeLibrary);
while (reader.Read ())
;
}
[Test]
public void Bug463267 ()
{
var datatypeLibrary = SetupMyDataProvider ();
XmlDocument xml = new XmlDocument ();
xml.LoadXml ("<root> <v2>1</v2> <v1>mytype</v1> </root>");
XmlDocument schemaXml = ReadDoc (TestResourceHelper.GetFullPathOfResource ("Test/XmlFiles/463267.rng"));
XmlReader reader = new RelaxngValidatingReader (new XmlNodeReader (xml), new XmlNodeReader (schemaXml), datatypeLibrary);
while (reader.Read ())
;
}
RelaxngDatatypeProvider SetupMyDataProvider ()
{
var datatypeLibrary = new RelaxngMergedProvider ();
datatypeLibrary [MyRngTypeProvider.Namespace] = new MyRngTypeProvider();
datatypeLibrary ["http://www.w3.org/2001/XMLSchema-datatypes"] = XsdDatatypeProvider.Instance;
datatypeLibrary [System.Xml.Schema.XmlSchema.Namespace] = XsdDatatypeProvider.Instance;
datatypeLibrary [String.Empty] = RelaxngMergedProvider.DefaultProvider [string.Empty];
return datatypeLibrary;
}
XmlDocument ReadDoc (string s)
{
var d = new XmlDocument ();
d.Load (s);
return d;
}
}
class MyRngTypeProvider : RelaxngDatatypeProvider
{
public static readonly string Namespace = "http://tempuri.org/mytypes";
public override RelaxngDatatype GetDatatype(string name, string ns, RelaxngParamList parameters)
{
switch (name)
{
case "mytype":
return new MyType();
}
return null;
}
}
class MyType : RelaxngDatatype
{
public override string Name {
get { return "mytype"; }
}
public override string NamespaceURI {
get { return MyRngTypeProvider.Namespace; }
}
public override object Parse (string text, System.Xml.XmlReader reader)
{
return text;
}
public override bool IsValid (string text, System.Xml.XmlReader reader)
{
return ((string) Parse (text, reader)) == "mytype";
}
}
}
|