Note that there are some explanatory texts on larger screens.

plurals
  1. POReplace multiple texts with their corresponding texts in XML using Python
    primarykey
    data
    text
    <p>How can I replace Japanese texts between with their corresponding English texts? I have a hundreds of AliasName that I need to replace. Since I am new to python and XML, a step by step instruction would be greatly appreciated.</p> <p>Here is how my xml file looks like:</p> <pre><code>&lt;Workspace&gt; &lt;Dataset&gt; &lt;DataElement&gt; &lt;Name&gt;POP&lt;/Name&gt; &lt;Fields&gt; &lt;Field&gt; &lt;Name&gt;State&lt;/Name&gt; &lt;AliasName&gt;?&lt;/AliasName&gt; # replace to &lt;AliasName&gt;State&lt;/AliasName&gt; &lt;/Field&gt; &lt;Field&gt; &lt;Name&gt;City&lt;/Name&gt; &lt;AliasName&gt;??&lt;/AliasName&gt; # replace to &lt;AliasName&gt;City&lt;/AliasName&gt; &lt;/Field&gt; (...) </code></pre> <p>Here is how far I have came. I created a dictionary, hoping that I can use it for replace(?)</p> <pre><code>&gt;&gt;&gt; x = ("State", "州", "City", "都市", "Town", "町") &gt;&gt;&gt; dic = dict(x[n:n+2] for n in xrange(0, len(x), 2)) &gt;&gt;&gt; print dic # Japanese appears strange in python GUI {'Town': '\x92\xac', 'City':'\x93s\x8es', 'State': '\x8fB'} </code></pre> <p>I also managed to select and display all Japanese texts between <code>&lt;AliasName&gt;&lt;/AliasName&gt;</code>.</p> <pre><code>from xml.dom import minidom xdoc = minidom.parse(r"D:\Desktop\python\src\sample.xml") workspace = xdoc.getElementsByTagName("AliasName") for i, element in enumerate(workspace): print (i, element.childNodes[0].data) </code></pre> <p>Fom here I am stuck. How can I replace and save updates on xml?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload