我想在C#中使用正則表達式來匹配xml文檔中的一個部分,並在標籤中包裝該部分。什麼是最好的方式來包裝一些XML文本標籤?
例如,我有本節:
<intro>
<p>this is the first section of content</p>
<p> this is another</p>
</intro>
,我希望它看起來像這樣:
<intro>
<bodyText>
<p> this is asdf</p>
<p> yada yada </p>
</bodyText>
</intro>
有什麼想法?
我正在考慮在C#中使用XPath類,或者只是通過閱讀文檔和使用正則表達式。我似乎無法想出任何方式。
這裏是一個嘗試:
StreamReader reader = new StreamReader(filePath);
string content = reader.ReadToEnd();
reader.Close();
/* The regex stuff would go here */
StreamWriter writer = new StreamWriter(filePath);
writer.Write(content);
writer.Close();
}
謝謝!
強制性鏈接:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – 2010-06-04 20:55:03
似乎你可能想要XSLT。 – jball 2010-06-04 20:56:27
您使用的是什麼版本的.NET? – 2010-06-04 23:53:02