[英]Error in xml document (1, 2) … was not expected
I've tried several of the suggestions found on other SO answers for this same error but nothing has helped. 我已经尝试过在其他SO答案中找到的一些建议,以解决相同的错误,但没有任何帮助。 Adding a namespace attr, using a blank namespace attr. 使用空白名称空间attr添加名称空间attr。 Loading the string into an xmlDocument then rewriting it back to an xmlWriter. 将字符串加载到xmlDocument中,然后将其重写回xmlWriter。 Using Serialazble instead of DataContract. 使用Serialazble代替DataContract。 Using xmlRoot attr with and without a namespace. 在带有和不带有名称空间的情况下使用xmlRoot attr。 Nothing works! 没用! Help. 救命。
I'm trying to instantiate a FillRequestExtended with the constructor that accepts an xml formatted string and always get the error Error in xml document (1, 2) 我正在尝试使用构造函数实例化FillRequestExtended,该构造函数接受xml格式的字符串,并始终在xml文档中出现错误Error(1、2)
The Inner Exception reads: "http://schemas.datacontract.org/2004/07/WdRx.Exactus.Objects'> was not expected." 内部异常显示为:“不希望出现http://schemas.datacontract.org/2004/07/WdRx.Exactus.Objects'>。”
The class looks like so: 该类如下所示:
namespace WdRx.Exactus.Objects
{
[DataContract]
public class FillRequestExtended : IExtendedData
{
[DataMember]
[XmlElement]
public KeyValuePair<string, string>[] Properties { get; set; }
[DataMember]
[XmlElement]
public List<Payment> PaymentItems { get; set; }
public FillRequestExtended()
{
}
public FillRequestExtended(string xml)
{
FillRequestExtended extendedData;
XmlSerializer xs = new XmlSerializer(typeof(FillRequestExtended));
using (StringReader sr = new StringReader(xml))
{
XmlReader reader = XmlReader.Create(sr);
extendedData = (FillRequestExtended)xs.Deserialize(reader);
}
Properties = extendedData.Properties;
PaymentItems = new List<Payment>(extendedData.PaymentItems);
}
}
}
The string passed in is serialized elsewhere with no issue and looks like so: 传入的字符串在其他地方都没有问题地被序列化,如下所示:
<FillRequestExtended xmlns=\"http://schemas.datacontract.org/2004/07/WdRx.Exactus.Objects\"
xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">
<PaymentItems>
<Payment>
<Amount>-43.95</Amount>
<Summary>CCP PAYMENT - AUTH:014910</Summary>
</Payment>
<Payment>
<Amount>0.00</Amount>
<Summary>Type: VIS Account: ************5793 Expires: 05/16 Authorization: 014910</Summary>
</Payment>
</PaymentItems>
<Properties xmlns:a=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">
<a:KeyValuePairOfstringstring>
<a:key>RxDcDate</a:key>
<a:value>20150414</a:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<a:key>RefillStatus</a:key>
<a:value>PROFILED</a:value>
</a:KeyValuePairOfstringstring>
</Properties>
</FillRequestExtended>
There are at least two different XML deserializers. 至少有两个不同的XML反序列化器。 By decorating the class with [DataContract] you are forcing it to use the WCF serializer. 通过用[DataContract]装饰类,可以强制其使用WCF序列化器。 In the deserialize code, you are using the normal XML object deserializer. 在反序列化代码中,您使用的是常规XML对象反序列化器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.