[I just found this group. I had originally posted this in
microsoft.public.xml but figured this group was more appropriate.
Please excuse the cross-post.]
I am trying to validate cXML documents against cXML.dtd using the
XmlValidatingReader. If I set the XMLValidatingReader's ValidatingType
to ValidationType.DTD, I get the following
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)."
I have seen a post regarding this issue, but still don't understand how
to resolve the it:
The post refers to: http://www.w3.org/2002/04/xml_bugs/#bug2 but this
still doesn't help me determine how to resolve the issue.
I am new to DTD but from the error message, Line 3009 in the DTD reads
as follows:
<!ELEMENT Message (Status? %cxml.messages;)>
Any advice is greatly appreciated.
Thanks,
Josh Blair
Evergreen, CO
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
T