I put together a nasty workaround/hack to get past this issue for the
time being. If anyone has a better way to validate a cXML document
againg the cXML.DTD, please let me know. I have included a code sample
that demonstrates how to get around the validation issue if anyone runs
into this issue in the future. Below the code sample is the output
that the code produces.
The cXML spec, sample documents, and sample DTD is located at
http://www.cxml.org/
This sample is being run against version cXML Version 1.2.014.
======= begin code snippet =======
using System;
using System.Xml;
using System.Xml.Schema;
using System.Data;
namespace XML_DTD_Example_CS
{
public class XML_DTD_Example
{
// If a validation error occurs, set this flag to false in the
validation event handler.
private static bool isValid = true;
public static void Main (string[] args)
{
try
{
//string xmlFilePath =
@"C:\Projects\XML_DTD_Example_CS\booksDTD.xml"; // is valid with valid
DTD
//string xmlFilePath =
@"C:\Projects\XML_DTD_Example_CS\OrderRequest.xml" ; // is valid but
..NET chokes on DTD
string xmlFilePath =
@"C:\Projects\XML_DTD_Example_CS\SamplecXMLPO.xml" ; // is valid but
..NET chokes on DTD
//string xmlFilePath =
@"C:\Projects\XML_DTD_Example_CS\OrderResponse.xml "; // is valid but
..NET chokes on DTD
// try to validate the cXML OrderRequest against the cXML.dtd
located at:
//
http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd
cXMLValidationTest(xmlFilePath);
}
catch(Exception e)
{
Console.WriteLine(e);
}
finally
{
Console.ReadLine();
}
}
/// <summary>
/// cXMLValidationTest01 tries to validate the cXML OrderRequests
against the cXML.dtd
/// </summary>
/// <param name="xmlFilePath">string</param>
private static void cXMLValidationTest(string xmlFilePath)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(xmlFilePath);
XmlValidatingReader xmlValidator = new
XmlValidatingReader(xmlDocument.OuterXml, XmlNodeType.Document, null);
xmlValidator.ValidationType = ValidationType.DTD;
xmlValidator.ValidationEventHandler += new
ValidationEventHandler(cXMLValidationEventHandler) ;
try
{
while (xmlValidator.Read()) {};
// Report whether the document is valid or invalid.
if (isValid)
Console.WriteLine("\nDocument: {0} is valid", xmlFilePath);
else
Console.WriteLine("\nDocument: {0} is invalid", xmlFilePath);
}
catch (System.Xml.Schema.XmlSchemaException e)
{
Console.WriteLine(e);
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
if (xmlValidator != null)
xmlValidator.Close();
}
}
public static void cXMLValidationEventHandler(object sender,
System.Xml.Schema.ValidationEventArgs args)
{
//System.Xml.Schema.XmlSchemaException: The parameter entity
replacement text must nest properly
//within markup declarations. An error occurred at
http://xml.cxml.org/schemas/cXML/1.2.014/cXML.dtd, (3009, 29).
if (args.Message.StartsWith("The parameter entity replacement
text"))
isValid = true;
else
isValid = false;
//System.Diagnostics.Debug.WriteLine(string.Format(" \nValidation
event ({0}, {1}):\n{2}", args.Exception.LineNumber,
args.Exception.LinePosition ,args.Message));
Console.WriteLine(string.Format("\nValidation event ({0},
{1}):\n{2}", args.Exception.LineNumber, args.Exception.LinePosition
,args.Message));
}
}
}
======= end code snippet =========
======= begin program output =========
XML_DTD_Example_CS.exe
Validation event (3009, 29):
The parameter entity replacement text must nest properly within markup
declarations. An error occurred at
http://xml.cxml.org/schemas/cXML/1.2.014/cXML.dtd, (3009, 29).
Validation event (3024, 29):
The parameter entity replacement text must nest properly within markup
declarations. An error occurred at
http://xml.cxml.org/schemas/cXML/1.2.014/cXML.dtd, (3024, 29).
Validation event (3835, 79):
The parameter entity replacement text must nest properly within markup
declarations. An error occurred at
http://xml.cxml.org/schemas/cXML/1.2.014/cXML.dtd, (3835, 79).
Document: C:\Projects\XML_DTD_Example_CS\SamplecXMLPO.xml is valid
======= end program output =========
HTH someone in the future,
Josh Blair
Evergreen, CO