tags:

views:

58

answers:

2

I have a XML file as shown below

<NewDataSet>
- <T>
  <P /> 
  <C>1</C> 
  <M /> 
  </T>
- <T>
  <P /> 
  <C>1</C> 
  <M /> 
  </T>
- <T>
  <P /> 
  <C>1</C> 
  <M /> 
  </T>
- <T>
  <P /> 
  <C>1</C> 
  <M /> 
  </T>
- <T>
  <P /> 
  <C>2</C> 
  <M>44</M> 
  </T>
- <T>
  <P /> 
  <C>2</C> 
  <M>45</M> 
  </T>
- <T>
  <P /> 
  <C>2</C> 
  <M>46</M> 
  </T>
</NewDataSet>

Question - Basicall i should remove the block

<T>
  <P /> 
  <C>1</C> 
  <M /> 
  </T>

that does not have <M> Value

A: 

You might want to take a look into Linq-to-XML

You could query for all XElements containing an empty M Element, and remove those from their parent XML Element.

Take for example:

from element in _yourXDocument.Descendants("NewDataSet")
select element
where element.Descendants("M").Value = String.Empty;

For .Net 2.0, use XmlDocument.

Webleeuw
I am using DotNet 2.0 framework whether Linq works here?????
Sathish
Ow crap, no it won't :(. Sorry, I was assuming you were using .Net 3.5
Webleeuw
+1  A: 

Load the whole document into an XmlDocument (or XDocument), select nodes with an XPath like /T[not(./M)] and delete them.

Anton Gogolev
I am using DotNet 2.0 framework can you please help me with a code
Sathish
XmlDocument is a .Net 2.0 class, please look it up on MSDN.
Webleeuw