Saving + Loading XML changes stored strings

Everything else that doesn't fall into one of the other PB categories.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Saving + Loading XML changes stored strings

Post 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 ""
Last edited by Lebostein on Fri Jun 29, 2018 10:37 am, edited 2 times in total.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Saving + Loading XML changes stored strings

Post 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 ""
drgolf
User
User
Posts: 90
Joined: Tue Mar 03, 2009 3:40 pm
Location: france

Re: Saving + Loading XML changes stored strings

Post 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 ""
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Saving + Loading XML changes stored strings

Post 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...
Post Reply