Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning a root elements other than root #329

Open
mqnifestkelvin opened this issue Jun 16, 2023 · 2 comments
Open

Assigning a root elements other than root #329

mqnifestkelvin opened this issue Jun 16, 2023 · 2 comments

Comments

@mqnifestkelvin
Copy link

When using the xmltodict.unparse() is a possibility of stating what the root element will be other than root when generating xml files. Thank you a response would be duly appreciated.
Also anytime I convert to form xmltodict, the values are changed from their actual values to string values, which is not what I intend, I need all the values to be exact in their conversion, is there away this is also done that I am not getting.
Thank you.

@mqnifestkelvin
Copy link
Author

Also is there a way we can add custom indent spacing to the resulting xml file?

@bfontaine
Copy link

Please share a sample of your data so we can reproduce your issue.

Also is there a way we can add custom indent spacing to the resulting xml file?

Yes, you can use pretty=True + indent="<custom indent>" to specify which string to use for indentation:

doc = { "doc": { "a": 1, "b": 2 } }

print(xmltodict.unparse(doc, pretty=True, indent=" ")) # one char
print(xmltodict.unparse(doc, pretty=True, indent="\t\t")) # two tabs

Results:

<?xml version="1.0" encoding="utf-8"?>
<doc>
 <a>1</a>
 <b>2</b>
</doc>
<?xml version="1.0" encoding="utf-8"?>
<doc>
		<a>1</a>
		<b>2</b>
</doc>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants