2016-04-01 11 views
1

レジストリキーを持つ属性regのxml行を削除して、新しいxmlファイルを作成したいと考えています。以下は参考用のコード例です。属性にレジストリキーを持つxml行を削除する

<file name="CMS_1.zip" version="1.01" reg="~/data/CMS_1.zip"/> 
<file name="CMS_2.zip" version="1.01" reg="~/data/CMS_2.zip"/> 
<file name="2012_3.swf" version="1.01" reg="~/data/Assets/CMS/V/Assets/FlashFiles/2012_3.swf"/> 
<file name="WS4.zip" version="1.01" reg="~/3b65566e-6y7c-a460-80bf-3612e36pp9ku/data/WS4.zip"/> 
<file name="Inv5.zip" version="1.02" reg="~/d465534r-a20c-558r-80bf-3612e687d45g/data/Inv5.zip"/> 
<file name="Inv6.zip" version="1.01" reg="~/4567j66e-y89o-4074-80bf-3612e247f1c7/data/Inv6.zip"/> 
<file name="Inv7.zip" version="1.01" reg="~/3b0po99e-a20c-4p91-80bf-pp9ku363f4r5/data/Inv7.zip"/> 

答えて

1

注意、あなたのXMLファイルは、ルート要素で有効である必要があります。

using System.Xml.Linq; 

var doc = XDocument.Parse(/*XML file content*/); // or use XDocument.Load(...) 
var pattern = @".*[0-9a-zA-Z]{8}\-[0-9a-zA-Z]{4}\-[0-9a-zA-Z]{4}\-[0-9a-zA-Z]{4}\-[0-9a-zA-Z]{12}.*"; 
doc.Descendants("file") 
    .Where(x => Regex.IsMatch((string)x.Attribute("reg"), pattern)) 
    .Remove(); 
var xmlContent = doc.ToString(); // or just doc.Save() 
関連する問題