+ Reply to Thread
Results 1 to 2 of 2

Thread: LINQ : Get collection of an attributes

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    15

    LINQ : Get collection of an attributes

    I have an xml file like that :
    Code:
    <BOOK Number="1" Name="Title">
        <CHP Number="1">
            <VER vnumber="1">This is the sentence 1.</VER>
            <VER vnumber="2">This is the sentence 2.</VER>
       </CHP>
       <CHP Number="2">
            <VER vnumber="1">Hello World 1.</VER>
            <VER vnumber="2">Hello World 2.</VER>
       </CHP>
       <!--And so on-->
    </BOOK>
    I want to ge the attribure "Number". The result:
    Code:
    Chapter={"CHP 1";"CHP 2",....};

  2. #2
    This will help you :
    Code:
    var chapters = xdoc.Descendants("CHP").Select(x => "CHP " + x.Attribute("Number").Value).ToList();

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts