coenen
12-15-2004, 05:39 PM
I would like to validate an xml data stream against an external xsd (IE xml stream does not reference it in header) that I have on my local web server in vb.net. I would also like to trap all the errors in validating the document and return them to the user.
Does anyone have some good sample code that would do this. Essentially I would like the functionality of the gotdotnet xsd validator at http://apps.gotdotnet.com/xmltools/...or/Default.aspx
I actually have code that reads an validates, only problem is once it finds one error and throws an exception it won't continue....I would like to know all of the errors in the document to return to the UI.
Here is my code.
---------------------------------------------
Dim objWorkingXML As New System.Xml.XmlDocument
Dim objValidateXML As System.Xml.XmlValidatingReader
Dim objSchemasColl As New System.Xml.Schema.XmlSchemaCollection
objSchemasColl.Add("", Server.MapPath("MYSchema.xsd"))
objValidateXML = New System.Xml.XmlValidatingReader(New System.Xml.XmlTextReader(MYXMLSTREAM))
'This is WHERE the validation occurs.. WHEN the XML Document READS through the validating reader
Try
objWorkingXML.Load(objValidateXML)
Catch ex As Exception
Response.Write(ex.Message.ToString)
Finally
'Close the stream
objValidateXML.Close()
End Try
'The document is valid
Response.Write("THE DOCUMENT IS VALID")
Does anyone have some good sample code that would do this. Essentially I would like the functionality of the gotdotnet xsd validator at http://apps.gotdotnet.com/xmltools/...or/Default.aspx
I actually have code that reads an validates, only problem is once it finds one error and throws an exception it won't continue....I would like to know all of the errors in the document to return to the UI.
Here is my code.
---------------------------------------------
Dim objWorkingXML As New System.Xml.XmlDocument
Dim objValidateXML As System.Xml.XmlValidatingReader
Dim objSchemasColl As New System.Xml.Schema.XmlSchemaCollection
objSchemasColl.Add("", Server.MapPath("MYSchema.xsd"))
objValidateXML = New System.Xml.XmlValidatingReader(New System.Xml.XmlTextReader(MYXMLSTREAM))
'This is WHERE the validation occurs.. WHEN the XML Document READS through the validating reader
Try
objWorkingXML.Load(objValidateXML)
Catch ex As Exception
Response.Write(ex.Message.ToString)
Finally
'Close the stream
objValidateXML.Close()
End Try
'The document is valid
Response.Write("THE DOCUMENT IS VALID")