Little John wrote:FormatXML() only should change the format, but must not change the content! So this is IMHO a bug in FormatXML().
I disagree, it's no bug.
You are basically telling FormatXML to reformat it.
What Freak could do is add another flag for a compact mode, the issue however is it would be very complicated to provide flags to match all ways people might want it to "compact" the output.
1st level nodes only, or 2nd and 3rd as well etc?
As was mentioned FormatXML is just a convenience feature, if you do not like it roll your own or use somebody elses if you have spesific needs beyond the scope of FormatXML.
Also if you read the link freak posted you'll see that it's possible to specify either "default" or "preserve" in a XML declaration.
But if the declaration is missing it's the same as default.
In other words what you want is preserve, but you also want preserve only on the <item> content, but not on the <root> content, and you'd probably want some other layout on <something> inside <item> nodes etc.
You should be aware that even with the unformatted PureBasic output of:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?><root><item id="1"> Wheelchair</item><item id="2">Skyscraper</item><item id="3">Computer</item></root>
(note the space in front of Wheelchair)
Any apps that read in that will most likely strip away that space, there is no guarantee that leading and trailing space is retained across apps.
Despite XLM's intentions (compared to HTML) you still need to be liberal in what you read in. (XML was created to be strict in that regard but it isn't sadly)
You say you do not want the content of a node to be changed (leading/trailing space etc), but you do want it to add a TAB in front of the item notes, but that in itself DOES change the content of the <root> by adding a TAB that is not really part of the content.
It's basically a catch-22 dilemma.
I'm sure that freak could add a check for xml:space in FormatXML so it keeps nodes with the declaration untouched but re-formats the rest, but this would bloat your xml a lot more obviously as that would have to stay there in the formated output as well (to ensure other apps/tools) do the same.
If you plan to let "humans" read and edit the output then you should be prepared to read back in a lot of weird things (extra spaces, tabs, or missing ones even).
If it's machine only then keeping it the very tight unformatted is the best really.
I'm sorry if this isn't helping but, the flaw is in XML and how everyone treat/interpret the specification, and W3C can't chnge this since it's "how things are done", probably the reason the added the xml:space extension to solve this issue.
You could always use CDATA though I guess...Not an ideal solution either.