473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

XmlValidatingReader and XmlResolver problems

Hi, I need some help...

Im trying to use XmlValidatingParser with a custom XmlResolver. Im
finding, however, that the custom resolver never gets called, and that
the XmlValidatingParser acts as a non-validating parser

I created a custom resolver called XmlBreakingResolver, whos GetEntity
and ResolveUri methods have breakpoints set in them along with
Debug.Assert(false). The breakpoints are never reached, and the the
Asserts never throw.

I know my data is good because, when I load the schema into the
Schemas property of the ValidatingReader instead of trying to use the
XmlResolver, all seems to work properly.

Searching on the web, I found a few references to XmlResolvers not
being called, but no solutions. has anyone struck this problem, and/or
can anyone suggest a solution...

Any help greatly appreciated...

Heres my code:

XmlValidatingReader vr = new XmlValidatingReader(new
XmlTextReader(input));
vr.XmlResolver = new XmlBreakingResolver();;
vr.Namespaces = true;
vr.ValidationType = ValidationType.Schema;

Console.WriteLine("------------------");
while (vr.Read())
{
XmlSchemaType type = vr.SchemaType as XmlSchemaType;
Console.WriteLine("{0} {1} {2}", vr.NodeType, vr.Name, type !=
null ? ":"+type.Name : "");
}
Console.WriteLine("------------------");
heres my data:

================== schema http://ReflectionXmlSerializer/1/1
==================
<?xml version="1.0" encoding="IBM437"?>
<xs:schema
xmlns:tns="http://ReflectionXmlSerializer/1/1"
elementFormDefault="qualified"
targetNamespace="http://ReflectionXmlSerializer/1/1"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="T" nillable="true" type="tns:T" />
<xs:complexType name="T">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="x" type="xs:int"
/>
<xs:element minOccurs="1" maxOccurs="1" name="y" type="xs:int"
/>
<xs:element minOccurs="1" maxOccurs="1" name="z" type="xs:int"
/>
<xs:element minOccurs="0" maxOccurs="1" name="b" type="tns:B" />
<xs:element minOccurs="0" maxOccurs="1" name="s"
type="tns:ArrayOfString"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="B">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="g"
type="xs:double" />
</xs:sequence>
<xs:attribute name="f" type="xs:float" use="required" />
</xs:complexType>
<xs:complexType name="ArrayOfString">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="string"
nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>

================== instance xml
<?xml version="1.0" encoding="IBM437"?>
<T xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ReflectionXmlSerializer/1/1">
<x>1335274566</x>
<y>1639139984</y>
<z>480098254</z>
<b f="0.8403818">
<g>0.21079391902815267</g>
</b>
<s>
<string>1710934067</string>
<string>137379920</string>
<string>1794435757</string>
</s>
</T>

Heres My resolver:
class XmlBreakingResolver : XmlResolver
{

System.Net.ICredentials _credentials = null;
public override System.Net.ICredentials Credentials
{
set { this._credentials = value; }
}
public override object GetEntity(Uri uri, string role, Type type)
{
Debug.Assert(false);
return null;
}

public override Uri ResolveUri(Uri uri, string relative)
{
Debug.Assert(false);
return base.ResolveUri(uri, relative);
}
}
Nov 12 '05 #1
4 3950
damien morton wrote:
Im trying to use XmlValidatingParser with a custom XmlResolver. Im
finding, however, that the custom resolver never gets called, and that
the XmlValidatingParser acts as a non-validating parser
Heres my code:

XmlValidatingReader vr = new XmlValidatingReader(new
XmlTextReader(input));
vr.XmlResolver = new XmlBreakingResolver();;
vr.Namespaces = true;
vr.ValidationType = ValidationType.Schema; ================== instance xml
<?xml version="1.0" encoding="IBM437"?>
<T xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ReflectionXmlSerializer/1/1">


Well, your XML document has no reference to a schema and you don't
provide schema for http://ReflectionXmlSerializer/1/1 namespace in your
C# code - how do you think XmlValidatingReader is supposed to figure out
where the schema is? So you hacve either add xsi:schemaLocation
attribute to your document or add the schema to
XmlValidatingReader.Schemas collection.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
damien morton wrote:
Im trying to use XmlValidatingParser with a custom XmlResolver. Im
finding, however, that the custom resolver never gets called, and that
the XmlValidatingParser acts as a non-validating parser
Heres my code:

XmlValidatingReader vr = new XmlValidatingReader(new
XmlTextReader(input));
vr.XmlResolver = new XmlBreakingResolver();;
vr.Namespaces = true;
vr.ValidationType = ValidationType.Schema; ================== instance xml
<?xml version="1.0" encoding="IBM437"?>
<T xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ReflectionXmlSerializer/1/1">


Well, your XML document has no reference to a schema and you don't
provide schema for http://ReflectionXmlSerializer/1/1 namespace in your
C# code - how do you think XmlValidatingReader is supposed to figure out
where the schema is? So you hacve either add xsi:schemaLocation
attribute to your document or add the schema to
XmlValidatingReader.Schemas collection.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #3
"Oleg Tkachenko [MVP]" <oleg@no_!spam!_please!tkachenko.com> wrote in message news:<eO**************@TK2MSFTNGP10.phx.gbl>...
damien morton wrote:

Well, your XML document has no reference to a schema and you don't
provide schema for http://ReflectionXmlSerializer/1/1 namespace in your
C# code - how do you think XmlValidatingReader is supposed to figure out
where the schema is? So you hacve either add xsi:schemaLocation
attribute to your document or add the schema to
XmlValidatingReader.Schemas collection.


Thanks for your response Oleg. I thought that XmlValidatingReader used
the namespace declarations to find the schema through the XmlResolver.
Obviously this belief was not correct.
Nov 12 '05 #4
"Oleg Tkachenko [MVP]" <oleg@no_!spam!_please!tkachenko.com> wrote in message news:<eO**************@TK2MSFTNGP10.phx.gbl>...
damien morton wrote:

Well, your XML document has no reference to a schema and you don't
provide schema for http://ReflectionXmlSerializer/1/1 namespace in your
C# code - how do you think XmlValidatingReader is supposed to figure out
where the schema is? So you hacve either add xsi:schemaLocation
attribute to your document or add the schema to
XmlValidatingReader.Schemas collection.


Thanks for your response Oleg. I thought that XmlValidatingReader used
the namespace declarations to find the schema through the XmlResolver.
Obviously this belief was not correct.
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Vlad | last post by:
I have the following code: I have a local copy of the DTD that I need to validate incoming XML documents against. The XML document has the <!DOCTYPE myname SYSTEM "myfile.dtd"> define. When the...
0
by: damien morton | last post by:
Hi, I need some help... Im trying to use XmlValidatingParser with a custom XmlResolver. Im finding, however, that the custom resolver never gets called, and that the XmlValidatingParser acts as...
2
by: Bennett Smith | last post by:
Could anyone within Microsoft comment on the status of the XmlResolver class in upcoming versions of the .NET framework? I am particularly interested in hearing about any improvements in how...
9
by: jason | last post by:
how do you use the XmlValidatingReader to validate an XML document that is passed into the XmlValidatingReader constructor? it looks like the normal process is to use an underlying reader, as...
5
by: Geoff | last post by:
I am using an XMLValidatingReader to validate an XML file received via a web service. I want to verify that the incoming file matches the XML schema. When testing the validation routine, the...
3
by: Nathan Alden | last post by:
Hi all. I have an XML schema that has a couple of <xs:import> tags that reference (using schemaLocation) schemas as embedded resources in a DLL. For example: <xs:import...
1
by: sorinuc | last post by:
Hi all, I'm quite desperate after so much time of frustration trying to validate an xml doc with a schema using XmlValidatingReader. I know I miss something but I cannot solve this for the life...
1
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST> xml file 2
12
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.