-
Notifications
You must be signed in to change notification settings - Fork 52
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
added pretty-print functionality #2
Conversation
Added pretty-print functions so that in addition to the XmlWritable toString, an indented "pretty-print" version of an XmlDocument could be created. Allows the user to change the indent string.
/** | ||
* Write the this object in a 'pretty' format to a `buffer`. | ||
*/ | ||
void prettyWriteTo(StringBuffer buffer, {String indent: ''}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a default implementation that delegates to 'writeTo' could avoid most overrides of this method. Alternatively the existing method with a named argument could maybe be reused?
I've added some comments. Generally I'd like all functionally to be fully tested. Also I am wondering how much automatic pretty printing XML is making sense at all? Doesn't that completely change the tree definition? It definitely does so for XHTML. |
Added the ability to output a formatted XML document tree, with indentation and newlines, when outputting children and siblings, respectively. As is the case with all 'pretty-print' capabilities of other libraries, the document tree output is not the same. The resultant text if parsed will have a tree that will contain more/less XmlText nodes than the original tree.
Conflicts: lib/xml/nodes/branch.dart lib/xml/nodes/cdata.dart lib/xml/nodes/comment.dart lib/xml/nodes/doctype.dart lib/xml/nodes/element.dart lib/xml/nodes/processing.dart lib/xml/utils/writable.dart
I incorporated changes for most of the comments/suggestions you made. Had some issues with git not syncing up correctly; hence commit (673ce52) and a "merge branch" commit. However, the changes are all there, and have been tested with both XML data using the XmlBuilder, as well as real XML data. As far as the pretty print not making sense - almost every useful XML library out there has that capability. I've used libraries in Flex, Python, Java, and C++ (both Xerces and Poco), and they all have it. So IMHO, that is necessary functionality if a XML library is to be maximally useful. You are correct in that it can/will change the tree definition; however, that is a well-known, usually acceptable side-effect. Having whitespace-only text nodes in most XML documents is usually ok; and the rendering/using application will often filter those out. |
added pretty-print functionality
Thank you for the contribution I've merged it. |
Added pretty-print functions so that in addition to the XmlWritable
toString, an indented "pretty-print" version of an XmlDocument could be
created. Allows the user to change the indent string.