Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

regex - Xml file, replacing numeric tag names with a valid ones

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 .

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I managed to that that with regular expression on notepad++, it wasn't that hard,

regex


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...