Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate against DTD without using XmlValidatingReader

Status
Not open for further replies.

nwruiz

Programmer
Jun 22, 2005
60
US
Hello,

I would like to validate the XmlDocument passed into the method below against a DTD. The XmlDocument was constructed in memory (DOM representation). Clearly, I do not need the XmlValidatingReader to read my file. However, I need a way to validate my newly generated XML document before transforming it.

Code:
' Transforms the XmlDocument (stored in memory) to Excel format, and saves it to "savePath".
    Public Sub ConvertXmlToExcel(ByVal doc As XmlDocument, ByVal savePath As String)
        Try
            'Create and load the XSL object
            Dim xslTrans As New XslTransform
            xslTrans.Load("../../SuezLoader/XML/IpbToExcel.xslt")

            'Create an XPathNavigator object and load XML data to be transformed
            Dim xPathNav As XPathNavigator = doc.CreateNavigator()

            'Create a writer to output the Excel file
            Dim txtWriter As New XmlTextWriter(savePath, System.Text.Encoding.UTF8)
            txtWriter.Formatting = Formatting.Indented
            txtWriter.WriteStartDocument()

            'Perform the transform and output the Excel file
            xslTrans.Transform(xPathNav, Nothing, txtWriter)
            Dim p As XmlResolver

            txtWriter.Close()
        Catch ex As Exception
            Debug.WriteLine(ex.ToString())
        End Try
    End Sub

The "Transform" method I call is also marked as "obsolete," and recommends that I use an XmlResolver. I understand that XmlResolver could validate against a DTD, but all of the documentation I have seen is either obscure or doesn't provide a useful example to me (grrr, MSDN). Thanks for your help.

Nick Ruiz
Associate Integrator
PPLSolutions IT Billing and Transactions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top