Exposing more API functions
I'd think it'd be helpful to expose the following API functions
doc.NewDocumentFromString(s string), based on:
https://github.com/beevik/etree/blob/4ec130554028d83ef14920b2661effbf0ee275e3/etree_test.go#L14-L22
and,
Element.WriteTo(w *bufio.Writer, s *WriteSettings), for debugging purposes, based on:
https://github.com/beevik/etree/blob/4ec130554028d83ef14920b2661effbf0ee275e3/etree.go#L1036-L1060
Please consider. thx.
In the interest of keeping the etree package minimal, I would prefer not to add NewDocumentFromString. It doesn't save the programmer much code.
Exposing a public WriteTo method from Element is an interesting idea. A couple things I'm unsure about:
- To use it, you would need to pass a
WriteSettingsparameter. This makes the method less easy to use. ForDocumenttypes, which already supportWriteTo, theWriteSettingsare embedded in the document, makingWriteTomuch easier to use in this case. - I need to evaluate whether other token types (e.g.,
CharData,Comment) would also need to supportWriteTofor consistency's sake.
Good call, thanks for considering. it'd be helpful, but may not be necessary...
@beevik, adding WriteTo method would be useful for me too for more efficient XML generation. For now I have to use Element.Copy() and create a new document with this single element so I can invoke WriteTo on it.
Also there is a thing to consider: if there are some unbound namespaces within the element, should Element.WriteTo() method find them and bound using information from parent elements in original Document...
Closing this issue, as it is quite old. There is also a pull request for it.