Bug found in XmlDocument when using doctype tag (such as for xhtml

G

Guest

Consider the following XML document :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
</body>
</html>

Let's see the doctype :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

If you use an XmlDocument to handel this xml file :
XmlDocument doc = new XmlDocument();
doc.Load( path ); //using doc.Load( string path )

the XmlDocument will MODIFY the doctype declaration, by appending []
e.g. :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"[]>

With that modification, you have a MALFORMED document, wich is NOT VALID !!

---------------------------------------------------------------------------------

Don't wait the next service pack to have a fix.
The easyest way to fix it, is to extends the XmlDocument class
And override the
public XmlDocumentType CreateDocumentType( string name, string publicId,
string systemId, string internalSubset ) method.

public override XmlDocumentType CreateDocumentType( string name,
string publicId, string systemId, string internalSubset )
{
if ( internalSubset != null && internalSubset.Length() == 0 )
return base.CreateDocumentType( name, publicId, systemId,
null );
else
return base.CreateDocumentType( name, publicId, systemId,
internalSubset );
}

Normally, if there are no internalSubset the .NET framework should call
this with null and not with an empty string !! Because it doesn't do it, we
have to do it !!


I hope that microsoft will consider and fix this bug.
I hope that this will help .NET programmers.

Yvesdm
 
Joined
Jul 10, 2012
Messages
1
Reaction score
0
hi i have used the code
public override XmlDocumentType CreateDocumentType(string name, string publicId, string systemId, string internalSubset)
{
if (internalSubset != null && internalSubset.Length() == 0)
return base.CreateDocumentType(name, publicId, systemId, null);
else
return base.CreateDocumentType(name, publicId, systemId, internalSubset);
}

in my C# code its not working, showing error:no suitable method found to override:(
can u pls guide me

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top