<books>
<book name="Christmas Cheer" price="10" />
<book name="Holiday Season" price="12" />
<book name="Eggnog Fun" price="5" special="Half Off" />
</books>
Ich mag würde dies mit Linq analysieren, und ich bin gespannt, welche Methoden andere Menschen besondere Handhabung verwenden. Meine derzeitige Arbeitsweise ist:Linq to XML Null Überprüfung von Attributen
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
};
Ich frage mich, ob es bessere Möglichkeiten gibt, das zu lösen.
Danke,
- Jared
Das ist super! Ich liebe es. Vielen Dank. – Howel