Hello,
I need to support XML deserialization of two very similar, yet different xml files.
File 1:
<?xml version="1.0" encoding="UTF-8"?>
<lr:LogReport xmlns:dcml="http://www.x1.org/schemas/Types/"
xmlns:ds="http://www.x3.org/2000/09/xmldsig#"
xmlns:lr="http://www.x.org/schemas/LogRecord/"
xmlns:xs="http://www.x3.org/2001/XMLSchema"
xmlns:xsi="http://www.x3.org/2001/XMLSchema-instance">
<lr:reportDate>2010-03-05T07:00:52-08:00</lr:reportDate>
File 2:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<LogReport xmlns="http://www.x.org/schemas/LogRecord"
xmlns:dcml="http://www.x1.org/schemas/Types"
xmlns:ds="http://www.x3.org/2000/09/xmldsig#"
xmlns:lr="http://www.x.org/schemas/LogRecord"
xmlns:xs="http://www.x3.org/2001/XMLSchema"
xmlns:xsi="http://www.x3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.x.org/schemas/LogRecord ./LogRecord.xsd http://www.x1.org/schemas/Types ./Types.xsd">
<lr:reportDate>2010-02-26T07:00:02-08:00</lr:reportDate>
Class Definition:
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://www.smpte-ra.org/schemas/430-4/2008/LogRecord"), _
System.Xml.Serialization.XmlRootAttribute("LogReport", [Namespace]:="http://www.smpte-ra.org/schemas/430-4/2008/LogRecord", IsNullable:=False)> _
Partial Public Class LogReport
Files matching File1 fail while files matching File2 succeed. The key difference is the trailing slash two of the namespace definitions.
Code Sample:
Dim oLogReport As New LogReport
Dim oType As System.Type = oLogReport.GetType
Dim oReader As System.Xml.XmlReader = Nothing
Dim oSerializer As New XmlSerializer(oType)
oReader = System.Xml.XmlReader.Create(sFileName)
oLogReport = CType(oSerializer.Deserialize(oReader), LogReport)
Error from File1:
{"<LogReport xmlns='http://www.x.org/schemas/LogRecord/'> was not expected."}
Already tried: http://stackoverflow.com/questions/1254544/how-do-i-specify-xml-serialization-attributes-to-support-namespace-prefixes-durin
These files come from a third-party so I cannot change the serialization process. Is there a way I can support both xml formats? Do I need two separate classes?
Thanks!