I'm using this code to try and load an xmlDocument into a serializable object
VB Code:
Public Shared Function LoadObjectFromXmlDoc(ByVal x As System.Xml.XmlDocument, ByVal objType As Type) As Object Try Dim tmpObj As Object Dim oXS As System.Xml.Serialization.XmlSerializer = New System.Xml.Serialization.XmlSerializer(objType) Dim oStm As New System.IO.MemoryStream() x.Save(oStm) tmpObj = oXS.Deserialize(oStm) oStm.Close() Return tmpObj Catch ex As Exception Return Nothing End Try End Function
But I keep getting an error saying "There is an error in XML document (0, 0).". The inner exception is "{"Root element is missing."}". But that's not true. It is a valid xml document. I serialize a class to create this document. This is a sample of what the xml file looks like when I save it to a file.
Code:<?xml version="1.0" encoding="utf-16" ?> - <ArrayOfSearchResults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - <SearchResults> <Show>Dream Team</Show> <Url>http://www.tv.com/dream-team/show/5430/summary.html?full_summary=1&tag=showspace_links;full_summary</Url> <Number>0</Number> </SearchResults> - <SearchResults> <Show>Time Team</Show> <Url>http://www.tv.com/time-team/show/21725/summary.html?full_summary=1&tag=showspace_links;full_summary</Url> <Number>0</Number> </SearchResults> </ArrayOfSearchResults>




Reply With Quote