I get the following XML from a database (modified data, but the structure is this)
<registro>
<header>
<codUsuario>XXX</codUsuario>
<codLojista>999</codLojista>
</header>
<parametros>
<consulta>XXX</consulta>
</parametros>
<ROWS>
<ROW>
<produto>1</produto>
<tab>10</tab>
</ROW>
<ROW>
<produto>2</produto>
<tab>10</tab>
</ROW>
</ROWS>
</registro>
I wrote a class:
public class registro
{
public Header header { get; set; }
public Parametros parametros { get; set;}
public List<Row> ROWS { get; set;}
}
public class Row
{
public string produto { get; set;}
public string tab { get; set;}
}
public class Parametros
{
public string consulta { get; set;}
}
public class Header
{
public string codUsuario { get; set;}
public string codLojista { get; set;}
}
Unknow node: ROW
I have already altered the class structure in several ways, used attributes to set the ElementName and nothing.
EDIT: I load the XML into the class using a resource I use to load other XML documents, including NF-e / CT-e / NFS-e
use this way:
registro reg = new registro();
ReadXML<registro>(ref reg, xml);
ReadXML method:
public void ReadXML<T>(ref T AObject, string AXml)
{
try
{
byte[] encodedString = Encoding.UTF8.GetBytes(AXml);
MemoryStream ms = new MemoryStream(encodedString);
ms.Flush();
ms.Position = 0;
XmlSerializer ser = new XmlSerializer(typeof(T));
ser.UnknownAttribute += new XmlAttributeEventHandler(Serializer_UnknownAttribute);
ser.UnknownElement += new XmlElementEventHandler(Serializer_UnknownElement);
ser.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode);
ser.UnreferencedObject += new UnreferencedObjectEventHandler(Serializer_UnreferencedObject);
AObject = (T)ser.Deserialize(ms);
}
catch (Exception ex)
{
throw new Exception("Erro ao serializar. Erro: " + ex.Message);
}
}