<books>
<book name="Christmas Cheer" price="10" />
<book name="Holiday Season" price="12" />
<book name="Eggnog Fun" price="5" special="Half Off" />
</books>
Me gustaría analizar esto utilizando linq y me gustaría saber qué métodos usan otras personas para manejarlos. Mi forma actual de trabajar con esto es:Linq To Xml Null Comprobación de los atributos
var books = from book in booksXml.Descendants("book")
let Name = book.Attribute("name") ?? new XAttribute("name", string.Empty)
let Price = book.Attribute("price") ?? new XAttribute("price", 0)
let Special = book.Attribute("special") ?? new XAttribute("special", string.Empty)
select new
{
Name = Name.Value,
Price = Convert.ToInt32(Price.Value),
Special = Special.Value
};
Me pregunto si hay mejores formas de solucionar esto.
Gracias,
- Jared
¡Eso es increíble! Lo amo. Gracias. – Howel