How to replace namespace in xml using XMLReader
Hi Guys,
I have a block of code that validates an xml file against a schema:
Code:
Private Function ValidateXmlWithXsd(xmlUri As String, xsdUri As String) As String
Dim strMessage As String = String.Empty
Try
Dim xmlSettings As New XmlReaderSettings()
xmlSettings.Schemas = New System.Xml.Schema.XmlSchemaSet()
xmlSettings.Schemas.Add("myschema", xsdUri)
xmlSettings.ValidationType = ValidationType.Schema
AddHandler xmlSettings.ValidationEventHandler, New ValidationEventHandler(AddressOf SettingsValidationEventHandler)
Dim reader As XmlReader = XmlReader.Create(xmlUri, xmlSettings)
While reader.Read()
End While
If nErrors > 0 Then
Status = False
strMessage = strErrorMsg
Else
Status = True
strMessage = "Validation Passed"
End If
reader.Close()
Return strMessage
Catch ex As Exception
Return False
Finally
End Try
End Function
This works great. However I've setup a namespace in the schema. When I am sent the xml file the namespace generated on the clients side is different. I need to change the namespace to the one I have in my schema. Please let me know how to do this.
Re: How to replace namespace in xml using XMLReader
Re: How to replace namespace in xml using XMLReader
thanks Matt. I've seen that article but it applies to an XDocument only