There is such code:

XDocument doc = new XDocument( new XElement("Cards", new XElement("Card", new XAttribute("number", labelCard.Text), listarticle.Select(i => new XElement("product", new XAttribute("article", i))), listcount.Select(a => new XAttribute("counts", a)) ))); doc.Save(@"../data/report/" + labelCard.Text + ".xml"); 

The compiler swears at the second XElement. Writes a "duplicate attribute. What am I doing wrong?

  • Has your question been resolved? - user227049

1 answer 1

Well, you see what you get at the output ..

 <?xml version="1.0" encoding="utf-8"?> <Cards> <Card number="..." counts="" counts="..." counts="..." counts="..."> <product article="..." /> <product article="..." /> </Card> </Cards> 

What am I doing wrong?

 listcount.Select(a => new XAttribute("counts", a)) 
  • So if I add for the last line, just new XAttribute ("counts", "1"). Then it displays XML without errors, where: <product article = "..." counts = "..." /> - user1667616
  • @ user1667616, so do you update your question and tell me what you want to see in the file? XML which structure? - Anton Komyshan