Try this code, which will list the values of the Campi attributes.
XmlDocument xml = new XmlDocument();
XmlTextReader reader = new XmlTextReader("Filename.xml");
xml.Load(reader);
XmlNodeList xnList = xml.SelectNodes("PrintDymo/Etichetta");
foreach (XmlNode xn in xnList)
{
XmlNodeList campiList = xn.SelectNodes("Campi");
foreach (XmlNode cn in campiList)
{
XmlAttributeCollection attribs = cn.Attributes;
Console.WriteLine($"attribute: {attribs[0].Value}");
}
}
The Campi elements do not contain anything except a single attribute, which as others have pointed out, does not make a lot of sense. An element should contain all valid attrivbutes together, something like:
<Campi Barcode ="123456789012" Data ="05/04/2023" Materiale="Pellame"/>
[edit]
Changed to
SelectNodes
.
[/edit]
[edit]
With Campi entries correctly formatted try:
XmlNodeList xnList = xml.SelectNodes("PrintDymo/Etichetta/Campi");;
foreach (XmlNode xn in xnList)
{
string firstName = xn.Attributes["Barcode"].InnerText;
string lastName = xn.Attributes["Materiale"].InnerText;
Console.WriteLine($"firstName: {firstName}, lastName: {lastName}");
}
[/edit]