我正在尝试将 XML 文档反序列化为 ac#DataContract 并遇到错误:
错误信息如下:
第 2 行位置 2 出错。从命名空间“http://ddex.net/xml/2010/ern-main/32”中期待元素“Ernmxml”。遇到名称为“NewReleaseMessage”的“元素”,命名空间“http:// /ddex.net/xml/2010/ern-main/32'
我还没有完成整个 DataContract,但这是我目前所拥有的:
namespace DdexCoverter
{
[DataContract]
public class Ernmxml
{
[IgnoreDataMemberAttribute] public string NewReleaseMessage;
[DataMember] public string PartId;
}
}
这是我的主程序:
class Program
{
static void Main(string[] args)
{
FileStream xmlstream = File.OpenRead(ConfigurationManager.AppSettings["xmlfilepath"]);
var xr = new XmlTextReader(ConfigurationManager.AppSettings["xmlfilepath"]);
var ddexxml = new Ernmxml();
var dcs = new DataContractSerializer(typeof(Ernmxml));
var ernmobj = (Ernmxml) dcs.ReadObject(xr);
}
}
}
在这一行生成错误: var ernmobj = (Ernmxml) dcs.ReadObject(xr);
XML 开头如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<ern:NewReleaseMessage xmlns:ern="http://ddex.net/xml/2010/ern-main/32"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
LanguageAndScriptCode="en"
xsi:schemaLocation="http://ddex.net/xml/2010/ern-main/32 http://ddex.net/xml/2010/ern-main/32/ern-main.xsd"
MessageSchemaVersionId="2010/ern-main/32">
<MessageHeader>
<MessageThreadId>PADPIDA</MessageThreadId>
<MessageId>PADPIDA</MessageId>
<MessageSender>
<PartyId>PADPIDA</PartyId>
<PartyName>
有人可以建议我如何解决此错误吗?