我想在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