1
我有下面的XML,其被存儲在字符串類型變量加載之前卸下從使用C#存儲在字符串型變量中的XML完整節點,我使用.NET 2.0:在的XMLDocument
<?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>
現在,在將它加載到XMLDocument之前,我只想加載標題中標題爲「07」且不包含「EKTA」的那些「Item」節點。
和C#代碼來做到這一點下面給出:
//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);
這有什麼錯去除'xDocument'節點?要移除節點,無論如何您都必須以這種或那種方式加載XML。使用像'// tcm:Item [contains(@ title,'07')] [!contains(@ title,'EKTA')]''這樣的xpath來選擇目標是很容易的。 – 2011-06-01 05:49:25
您也可以在字符串上運行正則表達式來替換與空字符串不匹配的字符串。 – cristobalito 2011-06-01 05:52:40
嗨安東,我的完整的XML是在字符串變量,請你讓我知道如何使用它的XPath。 – 2011-06-01 06:57:14