Unity Community


Results 1 to 19 of 19

  1. Posts
    32

    Read XML without document element

    Hi all

    I am trying to load XML in unity without a document element (I get it from a web service). The XML has the following form:

    [code]
    <virtualpatientscript>
    <act id="Introduction">
    <triggermap>
    <trigger_map_id>12886</trigger_map_id>
    <responses>
    <speech>Social_3.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Social</topic>
    <sentences>
    </virtualpatientscript>
    [code]


    Unity returns the following error which i think is related to the way the document is constructed. Is there any way to bypass that?

    XmlException: Document element did not appear. Line 1, position 1.
    Mono.Xml2.XmlTextReader.Read ()


  2. Posts
    736
    Dude, stop posting this over and over. Once is enough!


  3. Posts
    2,299
    Well what web service returned that to you?

    <triggermap> is not closed. <sentences> is not closed.

    So you want to tell Unity to ignore a broken document?


  4. Posts
    32
    This is the complete XML file. You can call it broken I guess.. Visual studio can read it just fine though. Is there anything I can do?

    <virtualpatientscript>
    <act id="Introduction">
    <triggermap>
    <trigger_map_id>12886</trigger_map_id>
    <responses>
    <speech>Social_3.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Social</topic>
    <sentences>
    <sentence>Hi Simone it is nice to meet you too</sentence>
    <sentence>
    </sentence>
    <sentence>Hi Simone it is a pleasure to meet you</sentence>
    <sentence>Hello there pleasure to meet you</sentence>
    <sentence>Hi Simone pleasure to meet you</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12889</trigger_map_id>
    <responses>
    <speech>Use_3.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>Which attractions of the castle are we going to visit</sentence>
    <sentence>I want more information for our current route</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12890</trigger_map_id>
    <responses>
    <speech>Use_5.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>if I get lost is there anyway to help me</sentence>
    <sentence>if I get lost what happens then</sentence>
    <sentence>if I get lost will you be able to help me</sentence>
    <sentence>What happens if I get lost on a route</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12926</trigger_map_id>
    <responses>
    <speech>Social_1.hap</speech>
    <br />
    <b>Warning</b>: mysql_fetch_array() expects parameter 1 to be resource, boolean given in <b>C:\xampp\htdocs\VirtualPeopleFactory\xml_script _exporter.php</b> on line <b>179</b><br /><morph name="" weight="0.30" delay="0" rampup="500" stable="1000" rampdown="500" /></responses>
    <triggers>
    </triggers>
    <topic>Social</topic>
    <sentences>
    <sentence>Hi Simone it is a beautiful day for a walk in the castle do not you think</sentence>
    <sentence>What a great day for a walk in the castle</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12927</trigger_map_id>
    <responses>
    <speech>Use_4.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>Why can not I create my own routes for the castle</sentence>
    <sentence>Why can not I choose the locations to visit myself</sentence>
    <sentence>Why can not I simply choose what to see</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12928</trigger_map_id>
    <responses>
    <speech>Use_6.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>Can you repeat your explanation on how to use the system</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12929</trigger_map_id>
    <responses>
    <speech>Social_2.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Social</topic>
    <sentences>
    <sentence>Hi Simone</sentence>
    <sentence>Hi there</sentence>
    <sentence>Hello Simone</sentence>
    <sentence>Hey there</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12932</trigger_map_id>
    <responses>
    <speech>Use_4_3.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>No problem you seem quite capable I am sure I will enjoy the tour</sentence>
    <sentence>No problem you seem to know what you are doing and I am sure I will enjoy the tour</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12933</trigger_map_id>
    <responses>
    <speech>Use_4_1.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>Hm can I trust my entertainment to your hands</sentence>
    <sentence>Can I trust your judgement </sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12934</trigger_map_id>
    <responses>
    <speech>Use_5_1.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>why can not you help me if I get lost</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12937</trigger_map_id>
    <responses>
    <speech>Use_7.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>I would like to start the tour please</sentence>
    <sentence>
    </sentence>
    <sentence>Great let us begin then</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12939</trigger_map_id>
    <responses>
    <speech>Use_4_2.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>
    </sentence>
    <sentence>I would prefer to choose the locations to visit myself</sentence>
    <sentence>OK but still I would like to choose what to see myself</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12940</trigger_map_id>
    <responses>
    <speech>Use_1.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>Yes please go on</sentence>
    <sentence>
    </sentence>
    <sentence>Yes please I have no idea how the system works</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>12941</trigger_map_id>
    <responses>
    <speech>Use_2.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Use_of_system</topic>
    <sentences>
    <sentence>I feel pretty comfortable with the use of the system</sentence>
    <sentence>
    </sentence>
    <sentence>No I know what I have to do </sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>17752</trigger_map_id>
    <responses>
    <speech>Social_4.hap</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>Social</topic>
    <sentences>
    <sentence>Hello beautiful how are you today</sentence>
    <sentence>Hello sexy how you doing</sentence>
    </sentences>
    </triggermap>
    </act>
    <act id="No Act Set">
    </act>
    <replacementlist>
    <map>
    <phrase>show</phrase>
    <replacewith>attraction</replacewith>
    </map>
    <map>
    <phrase>knowledge</phrase>
    <replacewith>information</replacewith>
    </map>
    <map>
    <phrase>info</phrase>
    <replacewith>information</replacewith>
    </map>
    <map>
    <phrase>knowing</phrase>
    <replacewith>know</replacewith>
    </map>
    <map>
    <phrase>how-do-you-do</phrase>
    <replacewith>hi</replacewith>
    </map>
    <map>
    <phrase>howdy</phrase>
    <replacewith>hi</replacewith>
    </map>
    <map>
    <phrase>Hawaii</phrase>
    <replacewith>hi</replacewith>
    </map>
    <map>
    <phrase>hullo</phrase>
    <replacewith>hi</replacewith>
    </map>
    <map>
    <phrase>Hawai'i</phrase>
    <replacewith>hi</replacewith>
    </map>
    <map>
    <phrase>Aloha State</phrase>
    <replacewith>hi</replacewith>
    </map>
    <map>
    <phrase>HI</phrase>
    <replacewith>hi</replacewith>
    </map>
    <map>
    <phrase>greeting</phrase>
    <replacewith>hi</replacewith>
    </map>
    <map>
    <phrase>salutation</phrase>
    <replacewith>hi</replacewith>
    </map>
    <map>
    <phrase>Begin</phrase>
    <replacewith>begin</replacewith>
    </map>
    <map>
    <phrase>glad</phrase>
    <replacewith>nice</replacewith>
    </map>
    <map>
    <phrase>to meet</phrase>
    <replacewith>to see</replacewith>
    </map>
    </replacementlist>
    </virtualpatientscript>
    Last edited by giannis; 04-12-2012 at 09:25 PM.


  5. Posts
    2,299
    Add this (if you didn't leave it off because you felt it was obvious):

    <?xml version="1.0" encoding="utf-8"?>

    So I would start with that.

    If that didn't fix it take a well known public XML schema and a short XML file generated from that XML schema and see if Unity handles it.

    As I really don't know your approach here is a couple of threads to help you out:

    (example simple test XML)
    http://files.unity3d.com/tom/orbitsi...olarSystem.xml
    the thread it's from:
    http://forum.unity3d.com/threads/253...ng-an-XML-file

    and then a more recent thread giving another approach:

    http://forum.unity3d.com/threads/131...ccessException

    I had fits building a WSDL and generating working XML from the Amazon Seller Central XML schemas in Eclipse because of all the nested complex types in those schemas.

    Then supposing that is fine then give Unity your XML schema and a shorter simplified XML output file and see if Unity can handle that.


  6. Posts
    2,299

    mysql_fetch_array

    I just noticed: It looks like a mismatch between the db field datatype and the XML data type.

    <br />
    <b>Warning</b>: mysql_fetch_array() expects parameter 1 to be resource, boolean given in <b>C:\xampp\htdocs\VirtualPeopleFactory\xml_scri pt _exporter.php</b> on line <b>179</b><br /><morph name="" weight="0.30" delay="0" rampup="500" stable="1000" rampdown="500" />


  7. Posts
    32
    OK I tried a different script with no problems this time. Unity returns the same error. My XML parsing is been handled by a dll API provided by the service provider. The idea is to add natural language capabilities to NPCs

    <virtualpatientscript>
    <act id="No Act Set">
    <triggermap>
    <trigger_map_id>63236</trigger_map_id>
    <responses>
    <speech>Hi am talking</speech>
    </responses>
    <triggers>
    </triggers>
    <topic>unassigned</topic>
    <sentences>
    <sentence>Hello there</sentence>
    </sentences>
    </triggermap>
    <triggermap>
    <trigger_map_id>63237</trigger_map_id>
    <responses>
    </responses>
    <triggers>
    </triggers>
    <topic>unassigned</topic>
    <sentences>
    </sentences>
    </triggermap>
    </act>
    <replacementlist>
    </replacementlist>
    </virtualpatientscript>


  8. Posts
    32
    OK apparently unity has no native XML support (shame really). This means that I need to parse the xml data through some external solution. Not good for unity I think as XML is been used everywhere


  9. Location
    USA
    Posts
    2,535
    Quote Originally Posted by giannis View Post
    OK apparently unity has no native XML support (shame really). This means that I need to parse the xml data through some external solution. Not good for unity I think as XML is been used everywhere
    You have access to System.Xml - not sure what you need beyond that.
    Fractured State - A moddable RTS game: Dev Blog | Facebook | Twitter | Youtube | ModDB

    Personal Twitter


  10. Posts
    736
    Unity doesn't need native support for XML; the .NET framework already provides it. There are numerous examples online of how to read full and partial xml in c#, so I don't understand what the issue is. Why don't you post the code that's giving you an error?


  11. Posts
    32
    The XML is been parsed through a dll provided by the web service. hr.getScript(currentscript); gets the script (you can see an example here http://vpf.cise.ufl.edu/VirtualPeopl...?script_id=710). Visual studio works fine but unity doesnt like it. its shame because I would like to add NLP to NPCs. It would be fun to talk to NPCs usign text instead of multiple choice menus.

    Code:  
    1. using UnityEngine;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Runtime.InteropServices;
    6. using VPFCommunicationsLibrary;
    7. using System.Text;
    8. using System.Collections.Specialized;
    9.  
    10. public class NLP : MonoBehaviour
    11. {
    12.     private VPFNaturalLanguageCommunicator hr = new VPFNaturalLanguageCommunicator();
    13.  
    14.  
    15.     void Start ()
    16.     {
    17.         hr.setAct("");
    18.         hr.setPreviousTopic("Say Hello");
    19.         hr.setHost("http://verg.cise.ufl.edu/VirtualPeopleFactory");
    20.         hr.setNumResponsesPerInput(10);
    21.  
    22.     }
    23.    
    24.     void Update () {
    25.     if (Input.GetKey(KeyCode.S)) {
    26.    windowopen = true;
    27.  
    28.                     }      
    29. }
    30. string response;
    31. bool windowopen = false;
    32. string currentscript = "710";
    33.    
    34. void OnGUI() {
    35.         if (windowopen){   
    36.         if (GUI.Button(new Rect(10, 10, 50, 50), "test"))
    37.         response = hr.getScript(currentscript)
    38.     print (response);}
    39.     }
    40. }


  12. Posts
    32
    Anybody out there? Any ideas?


  13. Posts
    736
    Quote Originally Posted by giannis View Post
    Anybody out there? Any ideas?
    I believe you may be encountering an issue where the dll is doing something underneath the scenes that isn't compatible in mono. Try catching the exception and checking all the inner exceptions to see if there are other errors lurking underneath


  14. Posts
    32
    The dll works fine.. I've used it several times in Visual studio. The problem is with Unity


  15. Location
    USA
    Posts
    2,535
    Quote Originally Posted by giannis View Post
    The dll works fine.. I've used it several times in Visual studio. The problem is with Unity
    Just because they work in Visual Studio doesn't mean they work everywhere. My guess is you're compiling against .NET in Visual Studio whereas Unity is compiling against Mono.

    I would again ask - why the plugin? You have System.Xml at your disposal so parse the data with that. Or better yet - try to parse it with your plugin, catch the exception (if any), and then parse it with System.Xml instead.
    Fractured State - A moddable RTS game: Dev Blog | Facebook | Twitter | Youtube | ModDB

    Personal Twitter


  16. Posts
    32
    Hi

    thanks for your input...

    <<try to parse it with your plugin, catch the exception (if any), and then parse it with System.Xml instead.>>

    How do it do that? Can you give me a specific example based on my code?


  17. Posts
    2,299
    Quote Originally Posted by giannis View Post
    Hi

    thanks for your input...

    <<try to parse it with your plugin, catch the exception (if any), and then parse it with System.Xml instead.>>

    How do it do that? Can you give me a specific example based on my code?
    Have you tried what's in this thread?

    http://forum.unity3d.com/threads/131...ccessException

    IEnumerator loadXML()
    {
    WWW webReq = new WWW(Application.dataPath + "/Dialogues/" + fileName);
    yield return webReq;
    XmlReader reader = XmlReader.Create(new StringReader(webReq.text));
    }
    and for appearance's sake you really should identify the file as XML with this line:

    <?xml version="1.0" encoding="utf-8"?>


  18. Posts
    736
    Quote Originally Posted by giannis View Post
    The dll works fine.. I've used it several times in Visual studio. The problem is with Unity
    The dll works fine when just in time compiled within visual studio, but when jit'd in Unity's mono i'm pretty sure it's failing. Like I said before, check all the inner exceptions.


  19. Posts
    2,299
    Quote Originally Posted by Diablo View Post
    The dll works fine when just in time compiled within visual studio, but when jit'd in Unity's mono i'm pretty sure it's failing. Like I said before, check all the inner exceptions.
    http://books.xmlschemata.org/relaxng/ch19-77151.html

    The lexical domain (xsd:NCName) of this datatype doesn't allow the definition of numerical identifiers or identifiers containing whitespace.

    By the way, I put your XML in a couple of online XML Schema generators and they didn't catch this.

    I have found to my frustration most of these things aren't caught by a parser til you try to use them at runtime, kind of like shell scripting.

    The safest thing I can recommend is never use white space in any XML name/attribute/type/id/etc... (I didn't go look up all the XML rules to verify this. The whitespace as value data within the tags is OK.)
    Last edited by goat; 04-14-2012 at 10:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •