Re: XmlValidatingReader DTD validation

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Yan Leshinsky (yanl_at_online.microsoft.com)
Date: 06/08/04


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)
>
> }
>
> }
>
>



Relevant Pages

  • Re: XPath to Line Number?
    ... how can I find the line-number of that node in the original XML ... bunch of validation rules, and outputs any errors and/or warnings. ... I am having trouble with finding a good DTD or Schema ... think it just makes DTD information available in the tree. ...
    (comp.lang.perl.modules)
  • Re: XPath to Line Number?
    ... how can I find the line-number of that node in the original XML ... bunch of validation rules, and outputs any errors and/or warnings. ... I am having trouble with finding a good DTD or Schema ...
    (comp.lang.perl.modules)
  • Re: 2 Questions about validations
    ... Validation is a process of checking validity. ... There are often rules that are clearly syntactic in nature but cannot be expressed in a DTD, or just have not been expressed in a DTD. ... Moreover, in some areas other than HTML, but pragmatically related to HTML, "validity" or "validation" is a technical term, with a meaning that is sufficiently similar to SGML or XML validity to confuse people. ...
    (comp.infosystems.www.authoring.html)
  • Re: Extended Markup?
    ... HTML _isn't_ that hard. ... Validation is based on measuring compliance with the DTD There's no ... "Not common practice 10 years ago" ...
    (alt.html)
  • Re: validate XML with DTD and Xerces: Non-whitespace characters
    ... If you want standalone validation with a DTD, ... I'll have a look on onsgmls. ...
    (comp.text.xml)