tags:

views:

22

answers:

0

This is my Xml File

<?xml version="1.0" encoding="utf-8" ?>
<root>

   <Child title="title1" >
     <grandChild>A</grandChild>
     <grandChild>B</grandChild>
     <grandChild>C</grandChild>
     <grandChild>D</grandChild>
   </Child>

   <Child title="title2" >
      <grandChild>E</grandChild>
      <grandChild>F</grandChild>
      <grandChild>G</grandChild>
      <grandChild>H</grandChild>`
   </Child>

</root>

string[] ar = new string[] { "A", "B", "H","NewItem" };
XElement xEle = new XElement("root",
        XDocument.Load(Server.MapPath("xmlfilepah"))
        .Elements("root")
        .Elements("Child ").Elements("grandChild")
        .Where(x => ar .Contains(x.Value))
        );

This Code giving me Output as:

<root>
  <grandChild>A</grandChild>
  <grandChild>B</grandChild>
  <grandChild>H</grandChild>
</root>

But I want

<root>
  <grandChild>A</grandChild>
  <grandChild>B</grandChild>
  <grandChild>H</grandChild>
  <grandChild>New Item</grandChild>
</root>