Search Unity

WebPlayer - save XML situated in the same domain

Discussion in 'Scripting' started by Eugenio, Aug 20, 2014.

  1. Eugenio

    Eugenio

    Joined:
    Mar 21, 2013
    Posts:
    197
    Hi guys.
    I have the need to load and save an XML file present in the same domain than the Unity3D WebPlayer application.
    Using
    Code (CSharp):
    1. XmlDocument.Load ("my URI")
    is working without any problem, but if I try to use
    Code (CSharp):
    1. XmlDocument.Save ("my URI")
    I'm getting the path not found exception. The strange thing is that to the URI, Unity will automatically add the local path of my machine (e.g. C:\Developing\Unity Project\www.mysite.com\myxmlfile.xml).
    I suppose that trying to use StreamWriter or other Mono class will not solve the problem... I saw a post on the forum in which someone suggested to use a PHP file to save the XML on the server... Is really this the only solution?

    Thank you very much :)
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    WebPlayer severely reduces your ability to interact with the host computer for security reason. You cannot save or load anything from its drives. The only way to save or load anything is with PlayerPrefs.

    You can send stuff over the internet, so saving something on a server is possible.
     
  3. Eugenio

    Eugenio

    Joined:
    Mar 21, 2013
    Posts:
    197
    Yes, I know this.
    The only thing is that I'm not able to save my local change on the server.
    I'll explain my workflow better:
    1. load an xml file from the server (working)
    2. modify locally the downloaded xml (working)
    3. caching the xml with playprefs on the local machine (working but I didn't mention it before)
    4. when everything is ready, save the changed xml on the server (NOT working)
    Basically nothing is local (apart from the playprefs stuff). My problem is that when I try to save the xml to the server, Unity is adding my local path to my URI (set as "http://myserver.com/myfile.xml") and it's telling me that the path is not correct launching the proper exception.
    My question was: can I use the XmlDocument.Save (URI) function to save the file, or do I have to create a PHP (or whatever) and use it to upload my changes?

    Sorry... maybe my question was a little bit messed up :p
     
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    You don't have access to any IO service, so it's not surprising that XmlDocument.Save fails.
    You will need to have a PHP server, and to send the file over by using the WWW class.
     
  5. Eugenio

    Eugenio

    Joined:
    Mar 21, 2013
    Posts:
    197
    Right... I thought it was the case, but asking to be sure will harm anyone... won't it, right? :p