I have got the XML below, which is stored in string type variable, and I am using .NET 2.0:
<?xml version="1.0"?>
<tcm:ListPublications xmlns:tcm="http://www.tridion.com/ContentManager/5.0" Managed="1">
<tcm:Item ID="tcm:0-437-1" Title="05 Main Australia Web Site (English)"/>
<tcm:Item ID="tcm:0-445-1" Title="06 Internal India Web Site (English)"/>
<tcm:Item ID="tcm:0-437-1" Title="07 EKTA Australia Web Site (English)"/>
<tcm:Item ID="tcm:0-445-1" Title="07 EKTA India Web Site (English)"/>
<tcm:Item ID="tcm:0-414-1" Title="07 Bahrain web Site (Arabic)"/>
<tcm:Item ID="tcm:0-272-1" Title="07 USA web Site (US English)"/>
<tcm:Item ID="tcm:0-279-1" Title="08 Bahrain web Site (English)"/>
<tcm:Item ID="tcm:0-392-1" Title="08 Belgium web Site (French)"/>
<tcm:Item ID="tcm:0-321-1" Title="08 Brazil web Site (English)"/>
</tcm:ListPublications>
Now, before loading it to my XMLDocument, I want to load only those “Item” nodes which are having Title=”07″ and does not contain “EKTA” in the title.
And the C# code to do this is given below:
//Creating the object of PublicatinBL class.
PublicationBL pubBL = new PublicationBL();
//All publications list XML.
//Here I am getting the whole XML as shown above.
string pubListXML = pubBL.getAllPublicationListXML();
XmlDocument xDocument = new XmlDocument();
//Loading the publication list XML.
//Here before loading the XML, I want to modify it as required above.
xDocument.LoadXml(pubListXML);
You could use LINQ to XML:
Or with LINQ syntax:
[Update] After .NET 2 was specified in the question.
In .NET 2 you can use XPath: