473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Trouble validating cXML documents with cXML.dtd using XmlValidatingReader

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/micro...2f271049d55950

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

Apr 6 '06 #1
2 7125
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

Apr 12 '06 #2
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

joshblair wrote:
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.

Jun 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ryan | last post by:
I have a very complex XDR schema that uses namespaces: xmlns="urn:schemas-microsoft-com:xml-data" xmlns:b="urn:schemas-microsoft-com:BizTalkServer" xmlns:d="urn:schemas-microsoft-com:datatypes"...
2
by: dotNetty | last post by:
Hi I have a problem with validating WSDL-Files using XMLValidatingReader. I'm adding all schemas in the <definitions>-Tag to the XmlValidatingReader.Schemas Property. and here is the Problem:...
2
by: Joris Janssens | last post by:
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...
0
by: Adam Smith | last post by:
Hello. I have a document schema which imports the schema of four other documents. The problem is that when validating a document in the multiple import scenario, I get a timeout and then it...
0
by: Shadow | last post by:
Hello, I am using the XmlValidatingReader to validate xml against an XSD schema. Some of the elements in the XSD have a max length set. I am having issues validating fields containing xml...
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
1
by: prefersgolfing | last post by:
I have a doc that that I am entering an incorrect value in a node that expects an restricted enumeration yet I can't get the ValidationEventHandler to fire. Shouldn't it fire if it finds an...
1
by: Chris Lieb | last post by:
I have an XML Schema file that I know is correct becuase I currently use it in a VB6 program to validate XML documents. Also, if I load an XML file into VS2005 that is not valid against this...
0
by: joshblair | last post by:
Hello, I am trying to post XML documents to a third party using the HttpWebRequest. This URL uses HTTPS (SSL) but I don't have a client certificate to deal with. Apparently they are using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.