Re: XmlValidatingReader DTD validation
From: Yan Leshinsky (yanl_at_online.microsoft.com)
Date: 06/08/04
- Next message: Oleg Tkachenko [MVP]: "Re: Xsl extension function and type coersion in .Net?"
- Previous message: Yan-Hong Huang[MSFT]: "RE: Problems with XML to Schema validation..."
- In reply to: Vlad: "XmlValidatingReader DTD validation"
- Next in thread: Oleg Tkachenko [MVP]: "Re: XmlValidatingReader DTD validation"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 8 Jun 2004 00:16:10 -0700
Your document has to have DOCTYPE to perform DTD validation. XmlResolver is
being used to resolve external entities, including external DTD of course.
There is not bug here.
Yan
"Vlad" <REMOVE_THISvladco@comcast.net> wrote in message
news:%23IfPlkKTEHA.2580@TK2MSFTNGP12.phx.gbl...
>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 following code is executed the XML gets resolved through the
> XMLResolver and gets correctly validated against the locally stored DTD
> file.
> The problem occurs when the incoming XML contains no DOCTYPE attribute.
> The
> resolver code never gets called and the validation does not occur at all.
> What am I doing wrong here? Is that a bug and there is no way to enforce
> the DTD even if the icoming XML file does not specify the DTD file?
>
> XmlDocument doc = new XmlDocument();
> XmlValidatingReader reader = new XmlValidatingReader(new
> XmlTextReader(stream));
>
> reader.XmlResolver = new MyDTDResolver();
>
> reader.ValidationType = ValidationType.DTD;
>
> doc.Load(reader);
>
> The XML document's stream is contained in the stream variable
>
> Here is MyDTDResolver declaration:
>
> private class MyDTDResolver:XmlUrlResolver
>
> {
>
> public override object GetEntity(Uri absoluteUri, string role, Type
> ofObjectToReturn)
>
> {
>
> return (returns a stream of the local copy of the DTD document that I
> validate XML against)
>
> }
>
> }
>
>
- Next message: Oleg Tkachenko [MVP]: "Re: Xsl extension function and type coersion in .Net?"
- Previous message: Yan-Hong Huang[MSFT]: "RE: Problems with XML to Schema validation..."
- In reply to: Vlad: "XmlValidatingReader DTD validation"
- Next in thread: Oleg Tkachenko [MVP]: "Re: XmlValidatingReader DTD validation"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|