XML TextOutputStream missing new line

Hello Everyone,

I am sure that I am missing something simple. The returned string of a transformed xml document is formatted correctly, and the saved TextOutputStream places all of the formatted string details on one line.

How do I retain the string formatting when saving the transformed xml into a file?

Here is some example code:

[code] Dim xml As New XmlDocument

Dim RootNode As XmlNode
RootNode = xml.AppendChild(xml.CreateElement(“Library”))

Dim BookNode As XmlNode
BookNode = RootNode.AppendChild(xml.CreateElement(“Book”))
BookNode.AppendChild(xml.CreateTextNode(“Access for Xojo”))

Dim XslString as string
XslString = “<?xml version=""1.0"" encoding=""UTF-8""?>”+_
“<xsl:transform version=”“1.0"” xmlns:xsl="“http://www.w3.org/1999/XSL/Transform”">" +_
“<xsl:output method=”“xml”" indent="“yes”" />" +_
“<xsl:template match=”"/"">" +_
“<xsl:copy-of select=”"/"" />" +_
“</xsl:template>” +_
“</xsl:transform>”

label1.Text = xml.Transform(XslString)

Dim f as FolderItem
Dim dlg as new SaveAsDialog
dlg.PromptText = “Save XML File”
f = dlg.showmodal()
Dim t as TextOutputStream = TextOutputStream.Create(f)
t.Write(ConvertEncoding(Label1.Text, Encodings.WindowsANSI))
t = nil[/code]

Label1.text shows the correctly formatted xml, however the saved file from TextOutputStream shows the xml code on one line (when opened in notepad). I have tried a few variations of t.Write and had no joy. This is with Windows 8.1 Xojo 2013 3.2.

Thanks for your suggestions!

Eugene

Eugene:

Label1.text shows the correctly formatted xml,
A Label control displays text with multiple lines ?
Strange

however the saved file from TextOutputStream shows the xml code on one line
t.WriteAll ?

(when opened in notepad).
Maybe NotePad is not the correct ‘application’ to use ?
What is NotePad ? I only know WordPad (with stypes) and Bloc Notes.

I have tried a few variations of t.Write and had no joy. This is with Windows 8.1 Xojo 2013 3.2.
Did you tried t.WriteLine ?

Did you try to change the value of XMLDocument.PreserveWhiteSpace to True ?

or better, do you try:
XMLDocument.SaveXML(YourFolderItem) ?

I hope these helps.

The relevant page in the documentation is: XMLDocument.SaveXML

Hi Emile,

Thanks for the comments :slight_smile:

[quote]>Label1.text shows the correctly formatted xml,
A Label control displays text with multiple lines ?
Strange[/quote]
When label1 has the appearance multiline set to ‘true’, then the xml is correctly formatted - it looks great!

[quote]>however the saved file from TextOutputStream shows the xml code on one line
t.WriteAll ?[/quote]
On Xojo’s Windows OS IDE, there is only the option for t.Write or T.Writeline, and neither option shows the data on multiline.

[quote]> (when opened in notepad).
Maybe NotePad is not the correct ‘application’ to use ?
What is NotePad ? I only know WordPad (with stypes) and Bloc Notes.[/quote]

Thanks for the suggestion. I tried notepad, write, and dreamweaver. All show the written data on one line.

Yes, and there appears to be no change - all data is on the same line.

[quote]or better, do you try:
XMLDocument.SaveXML(YourFolderItem) ?[/quote]
Another good thought. Tried this option and shows the data on a single line.

Good suggestions, but doesn’t seem to work. Are there any other possibilities that I should try?

Sincerely,

Eugene

t.WriteAll:

My mistake: that is TextInputStream.ReadAll !

Why: Encodings.WindowsANSI ?

Did you try Encodings.UTF8 ?

It looks to me (now) an Encoding problem. Something like a miscoded Return.
Windows use not the same Return than OS X (Linux status ?)

Putting the xml into the label and then pulling it back out is probably killing the EOL characters for your platform. Save the transformed xml in a string and write that to the file. Or use ReplaceLineEndings to correct the EOLs when you write it out.

In general: controls are not the best data storage medium as they can modify the data you are storing. You must take care when you use them that way. It is usually best to use controls as a display of some backed storage (MVC) where possible.

Hello,

[quote]Emile: Why: Encodings.WindowsANSI ?
Did you try Encodings.UTF8 ?[/quote]

LOL, my apologies, I am just used to using WindowsANSI encodings. Good suggestions!

I combined both Emile’s UTF8 encoding suggestion with Tim’s EOL suggestion and the saved file shows properly!

Thanks for your help you two! :slight_smile: