Get a collection of an attribute by linq

crimo1274

New Member
I have an xml file.\[code\]<BOOK bnumber="1" bname="Book"> <CHP cnumber="1"> <VER vnumber="1">This is the sentence 1.</VER> <VER vnumber="2">This is the sentence 2.</VER> <VER vnumber="3">This is the sentence 3.</VER> </CHP> <CHP cnumber="2"> <VER vnumber="1">Hello World 1.</VER> <VER vnumber="2">Hello World 2.</VER> <VER vnumber="3">Hello World 3.</VER> <VER vnumber="4">Hello World 4.</VER> </CHP> <!--MANY: Thousand records--></BOOK>\[/code\]I want to ge the attribure "cnumber". The result:\[code\]Chapter={"CHP 1";"CHP 2",....};\[/code\]My uncomplected code:\[code\]XDocument xdoc = XDocument.Load("Book.xml"); var temp = xdoc.Descendants("CHP").Where(x => x.Attribute("cnumber").Value != "0");\[/code\]Thanks.
 
Back
Top