如何在root声明名称空间时反序列化xml?

时间:2009-12-09 13:02:53

标签: asp.net xml namespaces serialization

我有xml:

<?xml version="1.0" encoding="UTF-8"?>
<wnio:Dokument xmlns:wnio="http://crd.gov.pl/wzor/2009/03/31/119/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ... >
</wnio:Dokument>

我想将其反序列化为object,例如:

[Serializable()]
[XmlRoot(Namespace = "wnio")]
public class Dokument
{ ... }

XmlSerializer构造函数应该包含哪些参数?

XmlSerializer serializer = new XmlSerializer(typeof(Dokument), 'What here?' );

XmlSerializer.Deserialize抱怨说它不期望元素http://crd.gov.pl/wzor/2009/03/31/119/'>。那是为什么?

1 个答案:

答案 0 :(得分:0)

wnio只是一个别名。试试这个:

[Serializable()]
[XmlRoot(Namespace = "http://crd.gov.pl/wzor/2009/03/31/119/")]
public class Dokument
{ ... }