Linq to XML question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kohli4life
    New Member
    • Apr 2010
    • 1

    Linq to XML question

    Hello All,

    Using LINQ to XML I am trying to get all nodes that contain the text of Errors within them. This node can be in any level of the XML document.
    Example:

    Code:
    <Users>
          <User>
               <FirstName>Tom</FirstName>
               <LastName>Won</LastName>
               <Error>Test 2</Error>
           </User>
          <User>
               <FirstName>Jim</FirstName>
               <LastName>Kim</LastName>
               <Error>Test 2</Error>
           </User>
           <Error>Test 3</Error>
    </Users>
    How do i return all 3 errors?

    Thanks
    Last edited by tlhintoq; Apr 25 '10, 04:34 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • Monomachus
    Recognized Expert New Member
    • Apr 2008
    • 127

    #2
    Originally posted by kohli4life
    Hello All,

    Using LINQ to XML I am trying to get all nodes that contain the text of Errors within them. This node can be in any level of the XML document.
    Example:

    Code:
    <Users>
          <User>
               <FirstName>Tom</FirstName>
               <LastName>Won</LastName>
               <Error>Test 2</Error>
           </User>
          <User>
               <FirstName>Jim</FirstName>
               <LastName>Kim</LastName>
               <Error>Test 2</Error>
           </User>
           <Error>Test 3</Error>
    </Users>
    How do i return all 3 errors?

    Thanks
    Hi,
    Please read the information from this blog post: Code4Food #5: How to get specific XML nodes using Linq to XML ?
    And also please read the MSDN articles about XElement, XDocument and XNode and how do we use them in real life.

    Comment

    Working...