Got more questions? Find advice on: ASP | SQL | Regular Expressions | Windows
in Search
Welcome to XmlAdvice Sign in | Join | Help

Trouble validating cXML documents with cXML.dtd using XmlValidatingReader

Last post 08-22-2006, 23:00 by joshblair. 5 replies.
Sort Posts: Previous Next
  •  04-06-2006, 14:17 16224

    Trouble validating cXML documents with cXML.dtd using XmlValidatingReader

    Hello,

    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


    Josh Blair
    Golden, CO
  •  08-21-2006, 18:06 21209 in reply to 16224

    Re: Trouble validating cXML documents with cXML.dtd using XmlValidatingReader

    Hi Josh,

     Did you get this resolved?  I am also trying to figure this one out too.

    I saw the same post,  http://www.w3.org/2002/04/xml_bugs/#bug2

    but I can't totally make out what I am supposed to do to fix the bug.

    I am using VB.NET

    Here is some code:

    Dim XmlSettings As New XmlReaderSettings()

    Dim XmlTextReader As XmlTextReader

    Dim XmlValidatorReader As XmlReader

    XmlSettings.ValidationType = ValidationType.DTD

    XmlSettings.ProhibitDtd = False

    Dim XmlTextReader As XmlTextReader

    Dim XmlValidatorReader As XmlReader

    XmlSettings.ValidationType = ValidationType.DTD

    XmlSettings.ProhibitDtd = False

    Dim XmlValidatorReader As XmlReader

    XmlSettings.ValidationType = ValidationType.DTD

    XmlSettings.ProhibitDtd = False

    XmlSettings.ValidationType = ValidationType.DTD

    XmlSettings.ProhibitDtd = False

    XmlSettings.IgnoreWhitespace = True

    XmlTextReader = New XmlTextReader(myFileNameLocation)

    XmlValidatorReader = XmlReader.Create(XmlTextReader, XmlSettings)

    Dim teststring As String

    True

    XmlTextReader = New XmlTextReader(myFileNameLocation)

    XmlValidatorReader = XmlReader.Create(XmlTextReader, XmlSettings)

    Dim teststring As String

    New XmlTextReader(myFileNameLocation)

    XmlValidatorReader = XmlReader.Create(XmlTextReader, XmlSettings)

    Dim teststring As String

    Dim teststring As String

    ' Read XML data

    ' Read XML data

    While XmlValidatorReader.Read()

    End While

     .

    End While

     .

     .

    .

    .

    Dim XmlSettings As New XmlReaderSettings()

    Dim XmlTextReader As XmlTextReader

    Dim XmlValidatorReader As XmlReader

    XmlSettings.ValidationType = ValidationType.DTD

    XmlSettings.ProhibitDtd = False

    Dim XmlTextReader As XmlTextReader

    Dim XmlValidatorReader As XmlReader

    XmlSettings.ValidationType = ValidationType.DTD

    XmlSettings.ProhibitDtd = False

    Dim XmlValidatorReader As XmlReader

    XmlSettings.ValidationType = ValidationType.DTD

    XmlSettings.ProhibitDtd = False

    XmlSettings.ValidationType = ValidationType.DTD

    XmlSettings.ProhibitDtd = False

    XmlSettings.IgnoreWhitespace = True

    XmlTextReader = New XmlTextReader(myFileNameLocation)

    XmlValidatorReader = XmlReader.Create(XmlTextReader, XmlSettings)

    Dim teststring As String

    True

    XmlTextReader = New XmlTextReader(myFileNameLocation)

    XmlValidatorReader = XmlReader.Create(XmlTextReader, XmlSettings)

    Dim teststring As String

    New XmlTextReader(myFileNameLocation)

    XmlValidatorReader = XmlReader.Create(XmlTextReader, XmlSettings)

    Dim teststring As String

    Dim teststring As String

    ' Read XML data

    ' Read XML data

    While XmlValidatorReader.Read()

    End While

     .

    End While

     .

     .

    .

    .

     

    Thanks,

    S.W.

  •  08-21-2006, 21:08 21284 in reply to 21209

    Re: Trouble validating cXML documents with cXML.dtd using XmlValidatingReader

    S.W.,

     I did get around it but it is just a workaround.

     http://groups.google.com/group/microsoft.public.dotnet.xml/msg/8ff133b8a48b007a

     Here is a link to the code sample that I put together.  Just a hack, but it works.  If you have trouble pulling up the article, let me know.  I'll email you a sample.

     I think that VS.NET 2005 may handle this better.  I haven't moved to VS.NET 2005 yet to test it out.

     If you find a better solution, please let me know,


    Josh Blair
    Golden, CO
  •  08-22-2006, 9:37 21566 in reply to 21284

    Re: Trouble validating cXML documents with cXML.dtd using XmlValidatingReader

    Hi Josh,

     Thanks for your response.

    If you wanted to bypass the validation of the DTD altogehter, you could set your validatator's validation type to none:

    xmlValidator.ValidationType = ValidationType.None;

    This works for VS 2005. I still want to validate against my local DTD.  I might have to update that.   I'll let you know if I learn more.

    Thanks,

    SW

     

  •  08-22-2006, 14:58 21755 in reply to 21566

    Re: Trouble validating cXML documents with cXML.dtd using XmlValidatingReader

    Josh,

    Did you try to validate your cXML with a prior DTD version?

    I think I got that orderrequest.xml example to work by using the 1.1.010 DTD.

    1.  I change my local DTD to a prior cXML version.  Not sure why a prior version works over the more recent.  Maybe the OrderRequest example is for Version 1.1. : http://www.cxml.org/files/downloads.cfm

    cXML 1.1 Specification (Version 1.1.010).

    and put somewhere locally on the server.

     

    2.  In code, when I read in the file, I replaced the DOCTYPE reference of the order cXML's coming in.

    Dim localDTD = "http://localhost:2576/WebSite3/cXML1_1.dtd"

    Dim otherDTDs_1 = "http://xml.cXML.org/schemas/cXML/1.1.010/cXML.dtd"

    Dim otherDTDs_2 = "http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd"

    Dim ByteFileString As String = Encoding.getString(ByteFile) '<------ByteFile is input from the function the xml in bytes()

    ByteFileString = ByteFileString.Replace(otherDTDs_1, localDTD)

    ByteFileString = ByteFileString.Replace(otherDTDs_2, localDTD)

    '\\Write to a temp file

    ByteFile = Encoding.GetBytes(ByteFileString)

    Dim lngLen As Long = ByteFile.Length

    objFileStream.Write(ByteFile, 0, CInt(lngLen))

    objFileStream.Flush()

    objFileStream.Close()

     

    3.  Then I call my ValidateFile function passing the temp file location

    Protected Function ValidateFile(ByVal myFileNameLocation As String) As Boolean


    'A file is validated by the DTD
       Dim XmlTextReader As XmlTextReader = Nothing

       Dim XmlValidatorReader As XmlReader = Nothing

    Try

       blnValidFile = True

       Dim XmlSettings As New XmlReaderSettings()

       XmlSettings.ValidationType = ValidationType.DTD

       XmlSettings.ProhibitDtd = False

       XmlSettings.IgnoreWhitespace = True

       XmlSettings.IgnoreComments = True

       XmlTextReader = New XmlTextReader(myFileNameLocation)

       XmlValidatorReader = XmlReader.Create(XmlTextReader, XmlSettings)

    ' Read XML data

       While XmlValidatorReader.Read

       End While

       XmlValidatorReader.Close()

        XmlValidatorReader = Nothing

        XmlTextReader.Close()

        XmlTextReader = Nothing


    Catch ex as exception

    '\\ If throws an error then invalid file

        blnValidFile=false

    'Error handler stuff, here 

    End Try

       Return blnValidFile

    End Function

     

    ===============end===============

    Seemed to work for me now.

    HTH

    SW

  •  08-22-2006, 23:00 21948 in reply to 21755

    Re: Trouble validating cXML documents with cXML.dtd using XmlValidatingReader

    S.W.,

    I haven't tried an older version of the DTD.  That is pretty cool.  I'll give it a shot.  Thanks for the tip.

     

     


    Josh Blair
    Golden, CO
View as RSS news feed in XML