0
I get the following XML from a database (modified data, but the structure is this same)
<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>
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;}
}
Summary is this, but when loading the xml in the class I have the following error:
Unknow Node: ROW
I have changed the structure of the class in several ways, I used attributes to set Elementname and nothing.
EDIT: I load XML into the class using a resource I use to load other XML documents, including NF-e/CT-e/NFS-e
use in 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);
}
}
How are you doing the parse? Give more details, code is missing
– DiegoSantos
edited and added the way I upload xml to the class (object)
– Marcos R. Weimer
Sorry but we are still missing the Parameters and Header class to take a look. If possible the error print tb
– DiegoSantos