No it doesn't help :(
Still when I call
reader = XmlReader.Create( new StringReader( xml ), settings );
it fails with the next exception:
System.NullReferenceException: Object reference not set to an instance of an
object
Would you please provide me your test code, so I'll check what don't I do
right?
Thank you a lot for your help!!!
Aleksey
> Try swapping the slash; the following works fine for me:
>
[quoted text clipped - 5 lines]
>
> Marc
Marc Gravell - 11 Feb 2008 09:57 GMT
I have (where there is also a Foo/Inner.xsd, included as per the
previous post); my "Oops" handler just writes a message to the console
to verify that my xml has been processed correctly (some valid, some
invalid):
XmlSchemaSet schema;
using(XmlReader reader =
XmlReader.Create("Foo/Bar/Outer.xsd")) {
schema = new XmlSchemaSet();
schema.Add(XmlSchema.Read(reader, Oops));
schema.Compile();
}
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas = schema;
settings.ValidationEventHandler += Oops;
settings.ValidationType = ValidationType.Schema;
using (XmlReader reader = XmlReader.Create("Sample.xml",
settings)) {
while (reader.Read()) { }
}
Marc
Aleksey Timonin - 11 Feb 2008 11:51 GMT
Thanks a lot, Marc!
It works now.
The problem was the next: I had pretty the same code with one defferance
that I used in StreamReader instead of XmlReader in the first "using"
statement.
Thank you a lot once again!
Aleksey
>I have (where there is also a Foo/Inner.xsd, included as per the previous
>post); my "Oops" handler just writes a message to the console to verify
[quoted text clipped - 17 lines]
>
> Marc
Marc Gravell - 11 Feb 2008 12:02 GMT
No problem; I can reproduce what you are seeing (StreamReader
failing); at a guess, perhaps the StreamReader doesn't have as much
clue where the original source location is, so it can't use
XmlResolver to find related files...
Interesting; I learn't something there (don't use StreamReader here
;-p) - so thanks for that.
Cheers,
Marc
Marc Gravell - 11 Feb 2008 12:19 GMT
(for completeness, this is the XmlReader.BaseURI property; there is
nothing equivalent for raw streams - plus you've gotta love the
consistent casing [URI vs Uri] and return type [System.String vs
System.Uri])
Marc