Results 1 to 3 of 3

Thread: How to replace namespace in xml using XMLReader

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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.

  2. #2
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: How to replace namespace in xml using XMLReader

    This article may be of some help to you: http://ludwigstuyck.wordpress.com/20...grammatically/
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  3. #3

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to replace namespace in xml using XMLReader

    thanks Matt. I've seen that article but it applies to an XDocument only

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width