Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trouble validating cXML documents with cXML.dtd using XmlValidatingReader

94 views
Skip to first unread message

josh

unread,
Apr 6, 2006, 11:41:11 AM4/6/06
to
Hi,

[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:

http://groups.google.com/group/microsoft.public.xml/browse_thread/thread/dc794aaf75905d3d/af2f271049d55950?lnk=st&q=XmlValidatingReader+DTD+cXML&rnum=1&hl=en#af2f271049d55950

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

joshblair

unread,
Apr 12, 2006, 11:10:20 AM4/12/06
to
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

Thomas S

unread,
Jun 10, 2006, 2:44:36 AM6/10/06
to
I'm having a problem with the cXML DTD, but I'm trying to get my code
that processes the PO Ack to IGNORE the DTD, which XMLReader and
XPathDocument actually download over the net everytime. I've tried
creating an XmlReaderSettings file with .ValidationType =
ValidationType.None, but it still insists on validating it anyway. If I
set ProhibitDtd = true then it throws an XMLException because no DTD is
allowed in the doc. I DON'T CARE if there's a DTD, I just want to
IGNORE it, but it won't. If I remove the DTD from the doc, it works
fine, but I don't want to have to code in a hack like that. Any way
just to ignore the DTD? I don't need it just for getting the PO Ack
response code.

T

0 new messages