question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: String required when indenting xml with namespaces

See original GitHub issue

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>

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
alek-syscommented, Jan 29, 2018

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.

0reactions
kanngardcommented, Feb 10, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with namespace while parsing XML using ElementTree
There are two problems on this line: a=tree.find('parent'). First, <parent> is not an immediate child of the root element. <parent> is a grandchild...
Read more >
xml.etree.ElementTree — The ElementTree XML API ...
Parsing XML​​ fromstring() parses XML from a string directly into an Element , which is the root element of the parsed tree. Other...
Read more >
XQuery, XSLT, and XPath Error Codes Namespace Document
It is a type error if the result of evaluating the sequence constructor cannot be converted to the required type. err:XTTE0510: It is...
Read more >
XML Schema: Understanding Namespaces - Oracle
By now it should be clear that to use a namespace, we first bind it with a prefix and then use that prefix...
Read more >
XML - Robot Framework
Parsing XML; Using lxml; Example; Finding elements with xpath; Element attributes; Handling XML namespaces; Boolean arguments; Importing ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found