Help required deserializing (C# / VB) an Xml File to an Object according to Schema - Where is shcema passed in?

Cognize
Cognize used Ask the Experts™
on
Hi,

I have a bug where an xml file is deserializing, but is missing some info from the xml file.

The file validates against a schema. What I want to do is make sure that I'm giving the deserializer the correct schema.

The schema is not referenced in the xml files (given to me by a 3rd party)

Is there a way of pointing the deserializer to a local copy of the schema to see if that helps?

Thanks
Public Sub SaveXMLFile(ByVal fileName As String, ByVal importObject As XMLImportObject)
        Dim xmlLoader As New XmlSerializer(GetType(XMLImportObject))
        Dim writer As New XmlTextWriter(fileName, System.Text.Encoding.UTF8)
        writer.Formatting = Formatting.Indented
        xmlLoader.Serialize(writer, importObject)
    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Are the missing XMLImportObject members marked Private, Protected, Friend or Shared?  XML serialization tends only to work with Public members.

Otherwise, are they marked with the XmlIgnore attribute, or with an incorrect XmlElement or XmlAttribute attribute?  These would cause the deserializer to ignore them or try to read them from a place that does not exist.

J.
Commented:
you are looking for a way to deserialize the xml file by validating it against schema

dim documentSchemaName as string = "http:\\lcoalhost\schema.xsd"

documentSchemaName = documentSchemaName & "?=" & DateTime.Now.Ticks.ToString

XmlData.Validate(<error event handler>)  ' where XmlData is the file that you want to deserialize

once validation is dione, you can deserialize it to the required object

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial