471,594 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

problem with validating XHTML 1.1-documents

I'm trying to write a program for validating XHTML 1.1-documents
against the XHTML 1.1 DTD (which is actually the same as validating an
XML-file) but I always get a "(404) Not found" error.

This is the program itself [C#]:

************************************************** ******************
using System;
using System.Xml;
using System.Xml.Schema;

namespace ValidatorTest {
class SimpleValidator {
[STAThread]
static void Main(string[] args) {
string url="http://users.telenet.be/flotspe/test.xhtml";
XmlTextReader reader=new XmlTextReader(url);
reader.Normalization=true;
XhtmlResolver myResolver=new XhtmlResolver();
reader.XmlResolver=myResolver;
XmlValidatingReader valReader=new XmlValidatingReader(reader);
valReader.ValidationEventHandler+=new
ValidationEventHandler(valHandler);
valReader.ValidationType = ValidationType.DTD;
while (valReader.Read()) {
}
valReader.Close();
}
private static void valHandler(object sender,
System.Xml.Schema.ValidationEventArgs e) {
Console.WriteLine("***Validation error***");
Console.WriteLine("\tSeverity:{0}", e.Severity);
Console.WriteLine("\tMessage :{0}", e.Message);

}
}
public class XhtmlResolver:XmlUrlResolver {
public override Uri ResolveUri(Uri baseUri, String relativeUri) {
Uri resolved=base.ResolveUri(baseUri,relativeUri);
Console.WriteLine("[" + resolved.AbsoluteUri + "]");
return resolved;
}
}
}
************************************************** ******************
And this is the output from my program:

************************************************** ******************
[http://users.telenet.be/flotspe/test.xhtml]
[http://users.telenet.be/flotspe/test.xhtml]
[http://users.telenet.be/flotspe/test.xhtml]
[http://users.telenet.be/flotspe/-//W...TML%201.1//EN]
[http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd]
[http://www.w3.org/TR/xhtml-modulariz...nlstyle-1.mod]
[http://www.w3.org/TR/xhtml-modulariz...amework-1.mod]
[http://www.w3.org/TR/xhtml-modulariz...tations-1.mod]
[http://www.w3.org/TR/xhtml-modulariz...tatypes-1.mod]
[http://www.w3.org/TR/xhtml-modulariz...l-qname-1.mod]
[http://www.w3.org/TR/xhtml-modulariz...-events-1.mod]
[http://www.w3.org/TR/xhtml-modulariz...attribs-1.mod]
[http://www.w3.org/TR/xhtml-modulariz...1-model-1.mod]

Unhandled Exception: System.Net.WebException: The remote server
returned an erro
r: (404) Not Found.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult
asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri,
ICredentials crede
ntials)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials
credentials)

at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role,
Type ofO
bjectToReturn)
at System.Xml.Schema.DtdParser.HandlePERef()
at System.Xml.Schema.DtdParser.ParseDtdContent()
at System.Xml.Schema.DtdParser.ParseConditionalSect()
at System.Xml.Schema.DtdParser.ParseDtdContent()
at System.Xml.Schema.DtdParser.ParseConditionalSect()
at System.Xml.Schema.DtdParser.ParseDtdContent()
at System.Xml.Schema.DtdParser.ParseDocTypeDecl()
at System.Xml.Schema.DtdParser.Parse()
at System.Xml.XmlTextReader.ParseDtd(XmlScanner scanner)
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseRoot()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlValidatingReader.ReadWithCollectText Token()
at System.Xml.XmlValidatingReader.Read()
at ValidatorTest.SimpleValidator.Main(String[] args) in
e:\flotspe\cs\visual
studio projects\validatortest\class1.cs:line 17
************************************************** ******************
<http://www.w3.org/TR/xhtml-modularization/DTD/xhtml11-model-1.mod>
doesn't exist, it should be
<http://www.w3.org/TR/xhtml11/DTD/xhtml11-model-1.mod>.
<http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod>
is listed as an absolute URL in
<http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd>.

<xhtml-notations-1.mod>, <xhtml-datatypes-1.mod>, <xhtml-qname-1.mod>,
<xhtml-events-1.mod>
and <xhtml-attribs-1.mod> are relative URL's in
<http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod>.

<xhtml11-model-1.mod> is also a relative URL but in
<http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd> but the program keeps
using <http://www.w3.org/TR/xhtml-modularization/DTD/> as the base URL
and hence the 404.
Can somebody tell me what I can do about this?

--
Joris "flotspe" Janssens *** http://inferno.xhtml.be/
gecontroleerd op virussen door m'n huisdokter

Nov 12 '05 #1
2 2379
Joris Janssens wrote:
Can somebody tell me what I can do about this?


I'd better download the DTD, fix it if needed and validate against this
local copy. This can be done with custom XmlResolver.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Oleg Tkachenko [MVP] schreef op 12/08/2004 :
Joris Janssens wrote:
Can somebody tell me what I can do about this?


I'd better download the DTD, fix it if needed and validate against this local
copy. This can be done with custom XmlResolver.

I just managed to "solve" it by using this custom XmlResolver:

public class Xhtml11Resolver:XmlUrlResolver {
public override Uri ResolveUri(Uri baseUri, string relativeUri) {
if (relativeUri.StartsWith("xhtml11")) {
baseUri=new Uri("http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
}
Uri resolved=base.ResolveUri(baseUri,relativeUri);
return resolved;
}
}

Although this is more an ugly hack than an elegant solution...

--
Joris "flotspe" Janssens *** http://inferno.xhtml.be/
The webmaster who says "ni"

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Tjerk Wolterink | last post: by
30 posts views Thread by Toni Mcintyre | last post: by
9 posts views Thread by rbronson1976 | last post: by
2 posts views Thread by Tjerk Wolterink | last post: by
4 posts views Thread by Enrika | last post: by
mickey0
1 post views Thread by mickey0 | last post: by
10 posts views Thread by Robert Huff | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

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.