Skip to content

Commit 7788ac8

Browse files
committed
add tests for preserving xml namespace
1 parent b6db361 commit 7788ac8

File tree

6 files changed

+1851
-42
lines changed

6 files changed

+1851
-42
lines changed

tableaudocumentapi/xfile.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def xml_open(filename, expected_root=None):
2828
# Is the file a zip (.twbx or .tdsx)
2929
if zipfile.is_zipfile(filename):
3030
tree = get_xml_from_archive(filename)
31-
else:
31+
else:
32+
_register_all_namespaces()
3233
tree = ET.parse(filename)
3334

3435
# Is the file a supported version
@@ -54,6 +55,9 @@ def temporary_directory(*args, **kwargs):
5455
finally:
5556
shutil.rmtree(d)
5657

58+
def _register_all_namespaces():
59+
# TO DO: should look at the file to find namespaces, not hardcode this one
60+
ET.register_namespace("user","http://www.tableausoftware.com/xml/user")
5761

5862
def find_file_in_zip(zip_file):
5963
'''Returns the twb/tds file from a Tableau packaged file format. Packaged
@@ -120,7 +124,9 @@ def save_into_archive(xml_tree, filename, new_filename=None):
120124

121125

122126
def _save_file(container_file, xml_tree, new_filename=None):
123-
127+
128+
_register_all_namespaces() # this shouldn't be necessary, should be done on open
129+
124130
if new_filename is None:
125131
new_filename = container_file
126132

test/assets/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)