Defining an XML formatting guideline #37665
Replies: 3 comments
-
White space within XML elements is significant within the XML infoset. So unless you have information (e.g. a schema) that tells you that white space is insignificant within the content of some element, you should not add or remove whitespace. The default should be not to mess with the white space that the user has put in their XML document. |
Beta Was this translation helpful? Give feedback.
-
If the user explicitly requests that an XML document be formatted, then there are some heuristics that can be applied. In particular, when an element has character children and all the character children are whitespace characters, it's usually the case that whitespace is not significant within the content of that element. |
Beta Was this translation helpful? Give feedback.
-
@AzeemMuzammil lets keep the default behavior as it is and do not format XML. We can add support for formatting options via VSCode and allow the user to enable XML formatting if required. We can also use it to provide other formatting options like the indentation length etc. |
Beta Was this translation helpful? Give feedback.
-
When it comes to formatting of a source code or any document, it is a matter of taste. And this is the same for formatting XML documents as well. Since the concern here is XML formatting, there's no any known universal guideline on how the XML should be formatted.
If an XML data to be sent across, then generally unnecessary white spaces would be eliminated before transfer in order to optimize transferring. This means no line breaks, no indentation, no comments. But there can be situations where the line breaks, indentations and comments has to be preserved like in source-codes, essays and poems.
And also If the XML document that is created will be read or modified on a regular basis, then obviously there should be some consideration given into keeping the document readable.
Since XML is a something natively supported by Ballerina Lang, it is a requirement to define an XML formatting guideline (as a part of the existing Ballerina Style Guide), that is consistent throughout the document and accepted across with proper reasoning.
The document below captures certain scenarios that frequently appears in an XML document and need to be decided on how the Ballerina formatting should work on those contexts.
XML Formatting
@jclark @hevayo Any suggestions or feedback will be highly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions