-
-
Save zed/7d8e1ebacf8ff119b1eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<workspace> | |
<dataset> | |
<dataelement> | |
<name> | |
POP | |
</name> | |
<fields> | |
<field> | |
<name> | |
State | |
</name> | |
<aliasname> | |
? | |
</aliasname> | |
</field> | |
<field> | |
<name> | |
City | |
</name> | |
<aliasname> | |
?? | |
</aliasname> | |
</field> | |
</fields> | |
</dataelement> | |
</dataset> | |
</workspace> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<workspace> | |
<dataset> | |
<dataelement> | |
<name> | |
POP | |
</name> | |
<fields> | |
<field> | |
<name> | |
State | |
</name> | |
<aliasname>州</aliasname> | |
</field> | |
<field> | |
<name> | |
City | |
</name> | |
<aliasname>都市</aliasname> | |
</field> | |
</fields> | |
</dataelement> | |
</dataset> | |
</workspace> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import xml.etree.cElementTree as etree | |
en2jp = {u"State": u"州", u"City": u"都市", u"Town": u"町"} # English -> Japanese | |
tree = etree.parse('input.xml') | |
for field in tree.iterfind('.//fields/field'): | |
name, alias = [field.find(tag) for tag in ['name', 'aliasname']] | |
if name is None or alias is None: continue | |
alias.text = en2jp.get(name.text.strip(), alias.text) | |
tree.write('output.xml', encoding='utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment