Page 1 of 2

Articy:Draft Runtime Conversion

Posted: Tue Feb 06, 2018 11:54 pm
by logiq121
I am having issues getting the XML file to load into the database. It's coming up with a NullReferenceError

Here is the Error: Image
Here is the code:

Code: Select all

ConverterPrefs myPrefs = new ConverterPrefs
        {
            EncodingType = EncodingType.ASCII,
            StageDirectionsAreSequences = false,
            ConvertDropdownsAs = ConverterPrefs.ConvertDropdownsModes.Ints,
            ConvertSlotsAs = ConverterPrefs.ConvertSlotsModes.ID,
            RecursionMode = ConverterPrefs.RecursionModes.On,
            FlowFragmentMode = ConverterPrefs.FlowFragmentModes.Quests,
            DirectConversationLinksToEntry1 = false,
            Overwrite = true
        };

        var database = ArticyConverter.ConvertXmlDataToDatabase("C:/Users/Leonard/Desktop/articy/cs_latest.xml", myPrefs);
        DialogueManager.AddDatabase(database);
        DialogueManager.SendUpdateTracker();

Re: Articy:Draft Runtime Conversion

Posted: Wed Feb 07, 2018 8:21 am
by Tony Li
Hi,

The method ArticyConverter.ConvertXmlDataToDatabase() expects that the string contains the entire XML content, not the filename of the XML file. You'll need to read the XML file into a string first -- for example, using System.IO.File.ReadAllText() -- and then pass that string to ArticyConverter.ConvertXmlDataToDatabase().

Re: Articy:Draft Runtime Conversion

Posted: Wed Feb 07, 2018 9:17 pm
by logiq121
When trying to place the string into the function I am getting this error:

XmlException: Text node cannot appear in this state. Line 1, position 1.

This is the code I am trying to run with.

Code: Select all

       
        ConverterPrefs myPrefs = new ConverterPrefs
        {
            EncodingType = EncodingType.UTF8,
            StageDirectionsAreSequences = false,
            ConvertDropdownsAs = ConverterPrefs.ConvertDropdownsModes.Ints,
            ConvertSlotsAs = ConverterPrefs.ConvertSlotsModes.ID,
            RecursionMode = ConverterPrefs.RecursionModes.On,
            FlowFragmentMode = ConverterPrefs.FlowFragmentModes.Quests,
            DirectConversationLinksToEntry1 = false,
            Overwrite = true
        };


        if (Application.internetReachability == NetworkReachability.NotReachable)
            yield return null;

        using (WWW www = new WWW(fileUrl))
        {
            Debug.Log("XML file Downloading");
            yield return www;

           
            if (www.isDone)
            {
                Debug.Log("Download Success");
                Debug.Log(www.text);
                var database = ArticyConverter.ConvertXmlDataToDatabase(www.text, myPrefs);
                DialogueManager.AddDatabase(database);
                DialogueManager.SendUpdateTracker();
            }

        }
        

Re: Articy:Draft Runtime Conversion

Posted: Wed Feb 07, 2018 9:27 pm
by Tony Li
Hi,

It may be an encoding issue. Try different encoding types to find the one that matches your source data.

It may also be that there's a blank space before the <?xml> tag. Please make sure that your text starts with "<?xml" as in the example below:

Code: Select all

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
If that doesn't help, would it be possible for you to send your XML file to me at tony (at) pixelcrushers.com? I'll be happy to take a look and test out the code.

Re: Articy:Draft Runtime Conversion

Posted: Wed Feb 07, 2018 11:25 pm
by logiq121
Sent.

Re: Articy:Draft Runtime Conversion

Posted: Thu Feb 08, 2018 8:14 am
by Tony Li
Thanks! I'll check this today and reply back here.

Re: Articy:Draft Runtime Conversion

Posted: Thu Feb 08, 2018 8:54 pm
by Tony Li
Hi Leo,

In case you didn't get my email, your code seems to work fine with your XML file if you adjust the code to provide the XML contents instead of the XML filename:

Code: Select all

var xml = System.IO.File.ReadAllText(@"C:\Users\Leonard\Desktop\articy\cs_latest.xml");
var database = ArticyConverter.ConvertXmlDataToDatabase(xml, myPrefs);

Re: Articy:Draft Runtime Conversion

Posted: Thu Feb 08, 2018 11:49 pm
by logiq121
When trying that method, I am getting a file not found. I've tried multiple locations and triple checking files/extensions. Even when I am able to output the xml as a string from the www attempt, I am still not able to get the convert function to work. :(

Re: Articy:Draft Runtime Conversion

Posted: Fri Feb 09, 2018 9:33 am
by Tony Li
Hi Leonard,

Please try the script below. After adding it to a scene, you can specify a local filename and a URL. If you set loadLocalFile true, it will load the local XML file. If you set it false, it will load from WWW. By default, I pointed the WWW version to a test file because I didn't want to expose your original XML file, but you can change it to your XML file. The script simply loads the XML and prints all the conversation titles to the Console.

You'll notice that it points to articy_test2.xml. This is a version of articy_test.xml which I've saved in UTF-8 without BOM format. The .NET library can't parse XML files that have been saved in UTF-8 with BOM format. If the file has BOM, it will raise the error you reported. (If you want to see the error, change the WWW filename to articy_test.xml without the 2 at the end. WWW preserves BOM, although reading the file locally seems to work fine either way.) The solution is to save your XML file in "UTF-8 without BOM" format. I use Notepad++. To do this, I went to the Encoding menu and changed it from "Encode in UTF-8-BOM" to "Encode in UTF-8".

LoadArticyRuntime.cs

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;
using PixelCrushers.DialogueSystem.Articy;

public class LoadArticyRuntime : MonoBehaviour
{

    public bool loadLocalFile = true;
    public string localFilename = @"C:\Users\Leonard\Desktop\articy\cs_latest.xml";
    public string fileUrl = @"http://pixelcrushers.com/dialogue_system/download/fileshare/articy_test2.xml";

    IEnumerator Start()
    {
        ConverterPrefs myPrefs = new ConverterPrefs
        {
            EncodingType = EncodingType.UTF8,
            StageDirectionsAreSequences = false,
            ConvertDropdownsAs = ConverterPrefs.ConvertDropdownsModes.Ints,
            ConvertSlotsAs = ConverterPrefs.ConvertSlotsModes.ID,
            RecursionMode = ConverterPrefs.RecursionModes.On,
            FlowFragmentMode = ConverterPrefs.FlowFragmentModes.Quests,
            DirectConversationLinksToEntry1 = false,
            Overwrite = true
        };

        DialogueDatabase database = null;

        if (loadLocalFile)
        {
            // Load local file:
            var xml = System.IO.File.ReadAllText(localFilename);
            Debug.Log(xml);
            database = ArticyConverter.ConvertXmlDataToDatabase(xml, myPrefs);
        }
        else
        {
            // Load from WWW:
            if (Application.internetReachability == NetworkReachability.NotReachable) yield return null;
            using (WWW www = new WWW(fileUrl))
            {
                Debug.Log("XML file Downloading");
                yield return www;

                if (www.isDone)
                {
                    Debug.Log("Download Success");
                    Debug.Log(www.text);
                    database = ArticyConverter.ConvertXmlDataToDatabase(www.text, myPrefs);
                }
            }
        }

        if (database == null)
        {
            Debug.Log("Database is null!");
        }
        else
        {
            Debug.Log("Conversations in database:");
            foreach (var conversation in database.conversations)
            {
                Debug.Log(conversation.Title);
            }
        }
    }
}

Re: Articy:Draft Runtime Conversion

Posted: Fri Feb 09, 2018 8:24 pm
by logiq121
It looks like your tip about saving the XML with UTF8 (WITHOUT BOM) Did the trick. I had to download notepadd ++ to make that happen. Thanks again.