Page 1 of 1

Saving + Loading XML changes stored strings

Posted: Fri Jun 29, 2018 10:31 am
by Lebostein
If you save a string with line breaks as a formated XML and you load this file again, then the string has changed. Is this a normal behaviour? Or a bug? It seems to me, information from inside the string and outside from the formatting are mixed...

Code: Select all

Input
"That is a test
That is PureBasic
A third line"

Output
"
    That is a test
    That is PureBasic
    A third line
  "

Code: Select all

EnableExplicit

Structure simple
  text.s
EndStructure

Define var.simple
var\text = "That is a test" + #CR$ + "That is PureBasic" + #CR$ + "A third line"

Debug "Input"
Debug #DQUOTE$ + var\text + #DQUOTE$
Debug ""

; Save XML
CreateXML(0)
InsertXMLStructure(RootXMLNode(0), var, simple)
FormatXML(0, #PB_XML_ReFormat)
SaveXML(0, "test.xml")
FreeXML(0)

; Load XML
CreateXML(0)
LoadXML(0, "test.xml")
ExtractXMLStructure(MainXMLNode(0), var, simple)
FreeXML(0)

Debug "Output"
Debug #DQUOTE$ + var\text + #DQUOTE$
Debug ""

Re: Saving + Loading XML changes stored strings

Posted: Fri Jun 29, 2018 10:35 am
by Lebostein
If you do the same with JSON, all is OK:

Code: Select all

EnableExplicit

Structure simple
  text.s
EndStructure

Define var.simple
var\text = "That is a test" + #CR$ + "That is PureBasic" + #CR$ + "A third line"

Debug "Input"
Debug #DQUOTE$ + var\text + #DQUOTE$
Debug ""

; Save XML
CreateJSON(0)
InsertJSONStructure(JSONValue(0), var, simple)
SaveJSON(0, "test.json", #PB_JSON_PrettyPrint)
FreeJSON(0)

; Load XML
CreateJSON(0)
LoadJSON(0, "test.json")
ExtractJSONStructure(JSONValue(0), var, simple)
FreeJSON(0)

Debug "Output"
Debug #DQUOTE$ + var\text + #DQUOTE$
Debug ""

Re: Saving + Loading XML changes stored strings

Posted: Fri Jun 29, 2018 1:54 pm
by drgolf
hello,
without formatxml, all is good :

Code: Select all

EnableExplicit

Structure simple
  text.s
EndStructure

Define var.simple
var\text = "That is a test" + #CR$ + "That is PureBasic" + #CR$ + "A third line"

Debug "Input"
Debug #DQUOTE$ + var\text + #DQUOTE$
Debug ""

; Save XML
CreateXML(0)
InsertXMLStructure(RootXMLNode(0), var, simple)
;FormatXML(0, #PB_XML_ReFormat,0)
SaveXML(0, GetPathPart(ProgramFilename())+"test.xml",#PB_XML_StringFormat )
FreeXML(0)

; Load XML
var\text=""
CreateXML(0)
LoadXML(0, GetPathPart(ProgramFilename())+"test.xml")
ExtractXMLStructure(MainXMLNode(0), var, simple)
FreeXML(0)

Debug "Output"
Debug #DQUOTE$+var\text+#DQUOTE$
Debug ""

Re: Saving + Loading XML changes stored strings

Posted: Sat Jun 30, 2018 10:55 am
by Lebostein
drgolf wrote:hello,
without formatxml, all is good :
Yes, exactly that IS my problem! It seems the XML formating function not only formats the XML structure, but also the stored content!! It adds line breaks and whitespaces inside an item definition <item>....</item>. That is a fail in my eyes. "Formating" means the visible things, but NOT changing the stored data...