所以我知道有很多与此相关的问题,我已经仔细阅读了这些问题,但仍然无法解决此问题的实例。
内部异常:
{"<CostSchedule xmlns='urn:un:unece:uncefact:data:standard:CostSchedule:3'> was not expected."}
我的XML文档是这样开始的:
<urn:CostSchedule
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:urn="urn:un:unece:uncefact:data:standard:CostSchedule:3"
xmlns:urn1="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:8"
xsi:schemaLocation="urn:un:unece:uncefact:data:standard:CostSchedule:3 http://www.unece.org/fileadmin/DAM/uncefact/data/standard/CostSchedule_3p0.xsd"
xmlns="urn:un:unece:uncefact:data:standard:CostSchedule:3">
我尝试使用上述文档架构反序列化为xsd.exe定义的类。课程开头是这样的:
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="urn:un:unece:uncefact:data:standard:CostSchedule:3"), _
System.Xml.Serialization.XmlRootAttribute([ElementName]:="CostSchedule", [Namespace]:="urn:un:unece:uncefact:data:standard:CostSchedule:3", IsNullable:=False)> _
Partial Public Class CostScheduleType
有谁可以指出我在这里失踪了什么?对我来说,看起来我已经为课程提供了所有必要的序列化标签,但我似乎无法做到这一点。
答案 0 :(得分:0)
想出来。
反序列化器要求我明确说明我反序列化的对象类型。
ElementsLocal = New CostScheduleType
'This was ElementsLocal = New Object before
Dim ser As New XmlSerializer(ElementsLocal.GetType)
Using fs As FileStream = New FileStream(LocalFileURI, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Using objStreamReader As New XmlTextReader(fs)
'If ser.CanDeserialize(objStreamReader) Then ElementsLocal = ser.Deserialize(objStreamReader)
ElementsLocal = ser.Deserialize(objStreamReader)