0

I have a XML sitemap file which looks like this

<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.example.com/web/201/hello_world1.html</loc>
</url>
<url>
<loc>http://www.example.com/web/202/hello_world2.html</loc>
</url>
<url>
<loc>http://www.example.com/web/203/hello_world3.html</loc>
</url>
</urlset>

and I want to change it to like

<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.example.com/web2/1/hello_world1.html</loc>
</url>
<url>
<loc>http://www.example.com/web2/1/hello_world2.html</loc>
</url>
<url>
<loc>http://www.example.com/web2/1/hello_world3.html</loc>
</url>
</urlset>

I want to change the different IDs 201, 202, 203 with just 1 ID, normal find and replace don't do that, Any idea how to do that in C# or suggest me a Regular Expression to do it in efficient way. Thanks

4

1 回答 1

1

将 XML 视为字符串并用正则表达式替换:

new Regex("web/[0-9]+/").Replace(youxmlstr, "web2/1/");
于 2012-07-26T19:09:22.103 回答