Я должен заменить старую конечную точку API новой, которую мне дали. Новый API возвращает xml, который выглядит следующим образом:
<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="https://api.com/">
<Model xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<IO>
<Code></Code>
<ActyErrMsgText></ActyErrMsgText>
<AddlDataToPrcsFlag></AddlDataToPrcsFlag>
<PrcsPgmName></PrcsPgmName>
<PgmLinkAreaText></PgmLinkAreaText>
</Model>
<Inquiry>
<Info>
<Mdl></Mdl>
<Prod></Prod>
...and so on
Мой объект такой:
public static class VinTest
{
[XmlRoot(ElementName = "Model", Namespace = "")]
public class Model
{
public IO IO { get; set; }
public Inquiry Inquiry{ get; set; }
}
public class IO
{
public string PrcsRtnStaCode { get; set; }
public string ActyErrMsgText { get; set; }
public string AddlDataToPrcsFlag { get; set; }
public string PrcsPgmName { get; set; }
public string PgmLinkAreaText { get; set; }
}
public class Inquiry
{
public Info Info { get; set; }
public Repair RepairInfo { get; set; }
}
public class Info
{
public string Code { get; set; }
public string Prod { get; set; }
}
}
Вот мой C# код для десериализации xml в мой object
using (var reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
{
responseText = reader.ReadToEnd();
byte[] byteArray = Encoding.ASCII.GetBytes(responseText);
MemoryStream stream = new MemoryStream(byteArray);
XmlSerializer serializer = newXmlSerializer(typeof(VinTest.Model));
var vinInfo = new VinTest.Model();
vinInfo = (VinTest.Model)serializer.Deserialize(stream);
return vinInfo;
}
System.InvalidOperationException: 'There is an error in XML document (1, 40).'
InvalidOperationException: <string xmlns='https://api.com/'> was not expected.
Итак, проблема, с которой я столкнулся, была https://api.com/ '>, не ожидалась. Как я могу пропустить эту строку в xml при десериализации в объект?