I have a bunch of XSD files in my assembly as embedded content that are read out via reflection and streams. My app creates the XML on the fly, and I want to validate it using the schema files embedded in my assembly.
Unfortunately, my problem is that every element is coming up invalid.
Here is the code:
Public Sub Validate(ByVal XmlText As String)Dim strmXML As New System.IO.Memor yStream(System. Text.Encoding.U TF8.GetBytes(Xm lText))Dim xmlVR As New XmlValidatingRe ader(New XmlTextReader(s trmXML))Dim xmlValidationEv entHandler As Xml.Schema.Vali dationEventHand lerxmlValidatio nEventHandler = AddressOf ValidationEvent 'Read common & shared schemas (imported)'Dim xmlCommon As New Xml.Schema.XmlS chema()'xmlComm on.Read(FedEx.F edExManager.Rea dFedExSchema(Tr ansactionSchema .Common), xmlValidationEv entHandler)Dim xmlShared As New Xml.Schema.XmlS chema()xmlShare d.Read(FedEx.Fe dExManager.Read FedExSchema(Tra nsactionSchema. Shared), xmlValidationEv entHandler)xmlS hared.Compile(x mlValidationEve ntHandler)'Read specific schemaDim xmlSchema As New Xml.Schema.XmlS chema()xmlSchem a.Read(Me.m_str mSchema, xmlValidationEv entHandler)xmlS chema.TargetNam espace = "http://www.fedex.com/fsmapi"xmlSchem a.Compile(xmlVa lidationEventHa ndler)'xmlVR.Sc hemas.Add(xmlCo mmon)xmlVR.Sche mas.Add(xmlShar ed)xmlVR.Schema s.Add(xmlSchema )xmlVR.Validati onType = Xml.ValidationT ype.SchemaAddHa ndler xmlVR.Validatio nEventHandler, xmlValidationEv entHandlerWhile xmlVR.Read() 'Debug.WriteLin e(xmlVR.Name)En d WhileEnd Sub
Unfortunately, my problem is that every element is coming up invalid.
Here is the code:
Public Sub Validate(ByVal XmlText As String)Dim strmXML As New System.IO.Memor yStream(System. Text.Encoding.U TF8.GetBytes(Xm lText))Dim xmlVR As New XmlValidatingRe ader(New XmlTextReader(s trmXML))Dim xmlValidationEv entHandler As Xml.Schema.Vali dationEventHand lerxmlValidatio nEventHandler = AddressOf ValidationEvent 'Read common & shared schemas (imported)'Dim xmlCommon As New Xml.Schema.XmlS chema()'xmlComm on.Read(FedEx.F edExManager.Rea dFedExSchema(Tr ansactionSchema .Common), xmlValidationEv entHandler)Dim xmlShared As New Xml.Schema.XmlS chema()xmlShare d.Read(FedEx.Fe dExManager.Read FedExSchema(Tra nsactionSchema. Shared), xmlValidationEv entHandler)xmlS hared.Compile(x mlValidationEve ntHandler)'Read specific schemaDim xmlSchema As New Xml.Schema.XmlS chema()xmlSchem a.Read(Me.m_str mSchema, xmlValidationEv entHandler)xmlS chema.TargetNam espace = "http://www.fedex.com/fsmapi"xmlSchem a.Compile(xmlVa lidationEventHa ndler)'xmlVR.Sc hemas.Add(xmlCo mmon)xmlVR.Sche mas.Add(xmlShar ed)xmlVR.Schema s.Add(xmlSchema )xmlVR.Validati onType = Xml.ValidationT ype.SchemaAddHa ndler xmlVR.Validatio nEventHandler, xmlValidationEv entHandlerWhile xmlVR.Read() 'Debug.WriteLin e(xmlVR.Name)En d WhileEnd Sub
Comment