[Solved] How to include a XML file on the exe?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Caronte3D
Addict
Addict
Posts: 1048
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

[Solved] How to include a XML file on the exe?

Post by Caronte3D »

No matter what I try, nothing works :?

Someone know how to use a xml file from data section?

Thanks in advance! :wink:

With this code I get: ""XML error on line 1: encoding specified in XML declaration is incorrect.""
The line 1 is: <?xml version="1.0" encoding="UTF-8"?>

Code: Select all

#Dialog = 0
#Xml = 0

XML$ = PeekS(?XmlInterface,-1,#PB_UTF8)
    
If CatchXML(#Xml, @XML$, StringByteLength(XML$)) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "window_1")
    
  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  
  Else
    MessageRequester("ERROR","Dialog creation error: " + DialogError(#Dialog))
    Debug "Dialog creation error: " + DialogError(#Dialog)
  EndIf
Else
  MessageRequester("ERROR","XML error on line " + XMLErrorLine(#Xml) + ": " + XMLError(#Xml))
  Debug "XML error on line " + XMLErrorLine(#Xml) + ": " + XMLError(#Xml)
EndIf

  CloseWindow(window_1)
    
EndProcedure

  
  ;--------------------------------------------- Data -------------------------------------------------
  DataSection
  XmlInterface:
    IncludeBinary "C:\Users\Usuario\Documents\PureBasic\file.xml"
    Data.u #Null
  EndDataSection
 
Last edited by Caronte3D on Sat Jan 11, 2020 4:53 pm, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to include a XML file on the exe? (This code is wron

Post by mk-soft »

You have already convert UTF8 to Unicode, Default of CatchXML is UTF8

Code: Select all

#Dialog = 0
#Xml = 0

XML$ = PeekS(?XmlInterfaceBegin,-1,#PB_UTF8)

If CatchXML(#Xml, @XML$, StringByteLength(XML$), 0, #PB_Unicode) And XMLStatus(#Xml) = #PB_XML_Success
;If CatchXML(#Xml, ?XmlInterfaceBegin, ?XmlInterfaceEnd - ?XmlInterfaceBegin) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "window_1")
    
    Repeat 
    Until WaitWindowEvent() = #PB_Event_CloseWindow
    
  Else
    MessageRequester("ERROR","Dialog creation error: " + DialogError(#Dialog))
    Debug "Dialog creation error: " + DialogError(#Dialog)
  EndIf
Else
  MessageRequester("ERROR","XML error on line " + XMLErrorLine(#Xml) + ": " + XMLError(#Xml))
  Debug "XML error on line " + XMLErrorLine(#Xml) + ": " + XMLError(#Xml)
EndIf


;--------------------------------------------- Data -------------------------------------------------
DataSection
  XmlInterfaceBegin:
  IncludeBinary "C:\Users\Usuario\Documents\PureBasic\file.xml"
  XmlInterfaceEnd:
  Data.u #Null
EndDataSection
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Caronte3D
Addict
Addict
Posts: 1048
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to include a XML file on the exe? (This code is wron

Post by Caronte3D »

mk-soft wrote:You have already convert UTF8 to Unicode, Default of CatchXML is UTF8
Thank you by your help, but now everything hangs (I need to use Ctrl+Alt+Del to quit) and doesn't show the window either :?

Here is a simple example file in case you or someone want to try:
https://drive.google.com/open?id=1pt3xG ... iggAOfbSpL

Any ideas? :?

P.D: The file was generated with the handy DialogDesign0r
User avatar
Kiffi
Addict
Addict
Posts: 1357
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: How to include a XML file on the exe? (This code is wron

Post by Kiffi »

works, if you remove #PB_Window_WindowCentered from the Xml-File

and use ParseXml() instead of CatchXml()

Code: Select all

XML$ = PeekS(?XmlInterface)
   
If ParseXML(#Xml, XML$) And XMLStatus(#Xml) = #PB_XML_Success
  [...]

Greetings ... Peter
Hygge
User avatar
Caronte3D
Addict
Addict
Posts: 1048
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to include a XML file on the exe? (This code is wron

Post by Caronte3D »

Solved! :idea:
This is strange... seems like a bug :arrow: The problem was by using: #PB_Window_WindowCentered, so when I switched to: #PB_Window_ScreenCentered, everything works now! :D

I think if no parent window, the #PB_Window_WindowCentered should act like #PB_Window_ScreenCentered.

Anyway I'm happy now :D

Thanks! :wink:
User avatar
Caronte3D
Addict
Addict
Posts: 1048
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to include a XML file on the exe? (This code is wron

Post by Caronte3D »

Kiffi wrote:works, if...
Thank you we wrote at once :lol:
User avatar
HeX0R
Addict
Addict
Posts: 992
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: [Solved] How to include a XML file on the exe?

Post by HeX0R »

The problem is, you first load the content of the XML into a string, which is unnecessary!
The moment PB stores it into a string, it will be unicode in memory and the encoding will no longer fit.
Just do it like this:

Code: Select all

#Dialog = 0
#Xml = 0

If CatchXML(#Xml, ?XmlInterface, ?XmlInterfaceEnd - ?XmlInterface) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "window_1")
   
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
 
  Else
    MessageRequester("ERROR","Dialog creation error: " + DialogError(#Dialog))
    Debug "Dialog creation error: " + DialogError(#Dialog)
  EndIf
Else
  MessageRequester("ERROR","XML error on line " + XMLErrorLine(#Xml) + ": " + XMLError(#Xml))
  Debug "XML error on line " + XMLErrorLine(#Xml) + ": " + XMLError(#Xml)
EndIf

CloseWindow(DialogWindow(#Dialog))
   

 
;--------------------------------------------- Data -------------------------------------------------
DataSection
XmlInterface:
  IncludeBinary "file.xml"
XmlInterfaceEnd:
EndDataSection
User avatar
Caronte3D
Addict
Addict
Posts: 1048
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: [Solved] How to include a XML file on the exe?

Post by Caronte3D »

HeX0R wrote:The problem is, you first load the content of the XML into a string, which is unnecessary!...
Thank you very much! :wink:
Post Reply