TypeError: String required when indenting xml with namespaces
When trying to indent XML including namespaces in Sublime 3 Build 3143, I get the following in the console:
Traceback (most recent call last):
File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 818, in run_
return self.run(edit)
File "indentxml in C:\Users\<username>\AppData\Roaming\Sublime Text 3\Installed Packages\Indent XML.sublime-package", line 47, in run
File "C:\Program Files\Sublime Text 3\sublime.py", line 823, in replace
sublime_api.view_replace(self.view_id, edit.edit_token, r, text)
TypeError: String required
Example of XML that generates the above error:
<xsd:element>
<xsd:annotation><xsd:documentation>
My documentation
</xsd:documentation></xsd:annotation>
</xsd:element>
+1
Fix for this is critical - most of the XML I work with includes namespaces. SAML metadata fails due to tags like "<md:EntityDescriptor ...".
Just to clarify - the "String required" error is misleading and I'm not sure where is it coming from. The real problem is that the piece of XML you are trying to format has to be a valid XML, i.e. it should define all the namespaces.
For example,
<xsd:element>
<xsd:annotation><xsd:documentation>
My documentation
</xsd:documentation></xsd:annotation>
</xsd:element>
technically is not a valid XML - xsd namespace is not defined. To make it 'parseable' and so 'indentable' namespaces need to be added:
<xsd:element xmlns:xsd="https://tempuri.org">
<xsd:annotation><xsd:documentation>
My documentation
</xsd:documentation></xsd:annotation>
</xsd:element>
So this problem can appear when you are trying to indent not a whole document, but part of it (or a selection).
I understand this explanation doesn't quite help to solve the problem, I just want to show that fixing this is tricky (namespaces need to be 'mocked' for indentiting or something). Also this is not in the list of my priorities at the moment, sorry. However I'll try to see if there is anything I can do quickly.
That makes sense, thank you for the reply.
In SAML metadata files, the namespace is always inferred, and I’ve never seen it explicitly declared, so I’ll wait for now. It might be nice to have a non-strict style for your indent plugin, where it only looks for matching open/close or self-closing tags and ignores unknown / undefined tags names.
Regardless, thank you for your work on this.
Regards,
Raun
From: Alexey Nesterov [mailto:[email protected]] Sent: Monday, January 29, 2018 1:57 AM To: alek-sys/sublimetext_indentxml [email protected] Cc: Raun Nohavitza [email protected]; Comment [email protected] Subject: Re: [alek-sys/sublimetext_indentxml] TypeError: String required when indenting xml with namespaces (#106)
Just to clarify - the "String required" error is misleading and I'm not sure where is it coming from. The real problem is that the piece of XML you are trying to format has to be a valid XML, i.e. it should define all the namespaces.
For example,
xsd:element
xsd:annotationxsd:documentation
My documentation
</xsd:documentation></xsd:annotation>
</xsd:element>
technically is not a valid XML - xsd namespace is not defined. To make it 'parseable' and so 'indentable' namespaces need to be added:
<xsd:element xmlns:xsd="https://tempuri.orghttps://tempuri.org">
xsd:annotationxsd:documentation
My documentation
</xsd:documentation></xsd:annotation>
</xsd:element>
So this problem can appear when you are trying to indent not a whole document, but part of it (or a selection).
I understand this explanation doesn't quite help to solve the problem, I just want to show that fixing this is tricky (namespaces need to be 'mocked' for indentiting or something). Also this is not in the list of my priorities at the moment, sorry. However I'll try to see if there is anything I can do quickly.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/alek-sys/sublimetext_indentxml/issues/106#issuecomment-361194655, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKtm2IhqC5-aGHLV6zPy64ck_uSBxv87ks5tPZXZgaJpZM4PYocl.
Thanks for clarifying. I often work on XML snippets and can not have the namespaces declared. So instead of working on XML files with thousands of lines, I only have a few lines to minimize the clutter and workload in Sublime. I see that this is actually a duplicate of #105 Found a plugin that handles my requirements, IndentX, https://github.com/socsieng/IndentX