Last active
March 19, 2021 14:06
-
-
Save RammusXu/5816e8779dbd2c70b2d4 to your computer and use it in GitHub Desktop.
Python Parser
This file contains hidden or 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
import xml.etree.ElementTree as ET | |
tree = ET.parse("arrays.xml") | |
ET.dump(tree) | |
tree.write("new_strins.xml") |
This file contains hidden or 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
#Before | |
<?xml version="1.0" encoding="utf-8"?> | |
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> | |
<string name="123" description="321" maxwidth="">Hello -> World</string> | |
#After | |
<resources xmlns:ns0="urn:oasis:names:tc:xliff:document:1.2"> | |
<string description="321" maxwidth="" name="123">Hello -> World</string> | |
This file contains hidden or 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
class PCParser(ET.XMLTreeBuilder): | |
""" For XMLTreeBuilder parsing comments""" | |
def __init__(self): | |
ET.XMLTreeBuilder.__init__(self) | |
# assumes ElementTree 1.2.X | |
self._parser.CommentHandler = self.handle_comment | |
def handle_comment(self, data): | |
self._target.start(ET.Comment, {}) | |
self._target.data(data) | |
self._target.end(ET.Comment) | |
tree = ET.parse("arrays.xml") | |
ET.dump(tree) | |
tree.write("new_strings.xml") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment