It is currently Tue Jun 18, 2019 12:16 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Saving + Loading XML changes stored strings
PostPosted: Fri Jun 29, 2018 10:31 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 11, 2004 7:07 am
Posts: 580
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:
Input
"That is a test
That is PureBasic
A third line"

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

Code:
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.

Top
 Profile  
Reply with quote  
 Post subject: Re: Saving + Loading XML changes stored strings
PostPosted: Fri Jun 29, 2018 10:35 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 11, 2004 7:07 am
Posts: 580
If you do the same with JSON, all is OK:
Code:
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 ""


Top
 Profile  
Reply with quote  
 Post subject: Re: Saving + Loading XML changes stored strings
PostPosted: Fri Jun 29, 2018 1:54 pm 
Offline
User
User

Joined: Tue Mar 03, 2009 3:40 pm
Posts: 47
Location: france
hello,
without formatxml, all is good :

Code:
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 ""


Top
 Profile  
Reply with quote  
 Post subject: Re: Saving + Loading XML changes stored strings
PostPosted: Sat Jun 30, 2018 10:55 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 11, 2004 7:07 am
Posts: 580
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...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye