I'm sending xml to a web service by building a string dynamically.
When my web service tries to validate the xml with a schema, I'm
getting the error "the root element is missing". If I use an xml file
saved to disk, I don't get an error.
Does anyone know what the problem could be?
- Cheryl
Public Function ValidateXML(ByVal sXML As String) As String
Dim strReader As StringReader
strReader = New StringReader(sXML)
Dim tr As XmlTextReader = New XmlTextReader(strReader)
Dim sc As XmlSchemaCollection = New XmlSchemaCollection
Dim vr As XmlValidatingReader = New XmlValidatingReader(tr)
Try
sc.Add(Nothing, "c:\FFRMA\Test.xsd")
vr.ValidationType = ValidationType.Schema
vr.Schemas.Add(sc)
AddHandler vr.ValidationEventHandler, AddressOf ValidationCallBack
While (vr.Read())
End While
sErrorMsg = "Success"
Catch ex As Exception
sErrorMsg = ex.Message & ":" & ex.Source
Finally
ValidateXML = sErrorMsg
End Try