本文介绍了Xml 文件,用有效的替换数字标签名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个无法验证的大型 xml 文件,因为它包含一些数字标签名称,如下所示:
i have a large xml file that couldn't be validated, because it contains some numeric tag names, here is how it looks:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<0>
<id>545f7bf982efa41a496379d2</id>
<org_id>1</org_id>
<status>open</status>
<name>Carrefour</name>
<address>1175 rue Guillaume Du Vair</address>
<created>1415543801.5059</created>
</0>
<1>
<id>545f7bf982efa41a496379d4</id>
<org_id>1</org_id>
<status>open</status>
<name>Carrefour Angers Grand Maine</name>
<address>rue Du Grand Launay</address>
<created>1415543801.5146</created>
</1>
<2>
<id>545f7bf982efa41a496379d6</id>
<org_id>1</org_id>
<status>open</status>
<name>Carrefour Angers Saint Serge</name>
<address>boulevard Gaston Ramon</address>
<created>1415543801.523</created>
</2>
<3>
<id>545f7bf982efa41a496379d8</id>
<org_id>1</org_id>
<status>open</status>
<name>Carrefour Anglet Bab2</name>
<address>avenue Jean Léon Laporte</address>
<created>1415543801.5302</created>
</3>
<4>
<id>545f7bf982efa41a496379da</id>
<org_id>1</org_id>
<status>open</status>
<name>Carrefour Angoulins</name>
<address>route De Rochefort</address>
<created>1415543801.5385</created>
</4>
<5>
<id>545f7bf982efa41a496379dc</id>
<org_id>1</org_id>
<status>open</status>
<name>Carrefour Annecy</name>
<address>134 avenue De Genève</address>
<created>1415543801.5458</created>
</5>
.
.
.
</root>
我想要做的是用有效的数字标签自动替换每个数字标签,例如:替换
What i am trying to do is to replace automatically each numeric tag with a valid one, for example: replace
Replace <0>...</0> with <A0>...</A0>
我的文件包含数千个这样的文件,有什么工具可以让我自动完成.
my file contains thousands of these, is there any tool i can use to do it automatically .
推荐答案
我在每个数字标签前加了xyz
I added xyz before each numeric tag
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
string input = File.ReadAllText(FILENAME);
string pattern = @"(?'open_tag'</?)(?'numbers'\d+)>";
MatchCollection matches = Regex.Matches(input, pattern);
input = Regex.Replace(input, pattern, "${open_tag}" + "xyz" + "${numbers}" + ">");
}
这篇关于Xml 文件,用有效的替换数字标签名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!