Search Unity

Problem when loading XML at runtime.

Discussion in 'Scripting' started by Kucrapok, Jun 28, 2012.

  1. Kucrapok

    Kucrapok

    Joined:
    May 2, 2011
    Posts:
    6
    Hi everyone, i'm starting a bullet hell game with Unity and I've started using BulletML library to do some missile patern. The bulletML library use XML to create patern. At some point in the BulletMLParser, we do this to load the xml

    XmlReaderSettings settings = new XmlReaderSettings();
    tree = null;
    settings.ProhibitDtd = false;
    settings.ValidationType = ValidationType.DTD;
    TextAsset asset = Resources.Load(xmlFileName) as TextAsset;
    ->//XmlReader reader = XmlTextReader.Create(new StringReader(asset.text),settings);
    ->XmlReader reader = XmlTextReader.Create(xmlFileName, settings);
    BulletMLParser parser = new BulletMLParser();

    while (reader.Read())
    ...

    When I'm in the editor, everything works perfectly. The problem is when i'm trying to build and run the project. The xml is not loaded correctly.

    I've searched many hours last night and I found some topics about my problem. I tried to put my xml like this in the project to use the "Resources.load(myfile) as TextAsset" command.

    Myproject/Assets/Ressources/myfile.xml

    When I tried running the .exe, I saw some errors in the log.

    NotImplementedException: The requested feature is not implemented.
    at System.Xml.DTDReader.ReadAttributeDefinition () [0x00000] in /Applications/buildAgent/work/3df08680c6f85295/mcs/class/System.XML/System.Xml/DTDReader.cs:940
    at System.Xml.DTDReader.ReadAttListDecl () [0x00093] in /Applications/buildAgent/work/3df08680c6f85295/mcs/class/System.XML/System.Xml/DTDReader.cs:913
    at System.Xml.DTDReader.CompileDeclaration () [0x00177] in /Applications/buildAgent/work/3df08680c6f85295/mcs/class/System.XML/System.Xml/DTDReader.cs:306
    at System.Xml.DTDReader.ProcessDTDSubset () [0x000dc] in /Applications/buildAgent/work/3df08680c6f85295/mcs/class/System.XML/System.Xml/DTDReader.cs:234

    So, I think the DTD isn't implemented for running time :X because the xml worked just fine in the editor.

    I also tried puting the xml in the TestData folder.
    My second idea was to try something else than using XMLReader object. I might try Xml document instead.

    My configuration is
    Windows 7 64 bit
    Unity editor 3.5.0
     
  2. apparition

    apparition

    Joined:
    Jan 11, 2012
    Posts:
    120
    I know this doesn't answer your question but do you really need to process the DTD in the game? Isn't it mainly for validation?
     
  3. szi_John

    szi_John

    Joined:
    Feb 10, 2012
    Posts:
    70
    Not sure if this will help but..
    .
    Normally in my gameobjects that need to do some kind of xml configurations i have a ref to a text asset
    Code (csharp):
    1.  
    2. public TextAsset xmlTextToRead;
    3.  
    then when i read the code i use System.Xml 's classes.
    i haven't compiled this but i'll give it a go without my favorite IDE
    Code (csharp):
    1.  
    2. XmlDocument xmlDoc = new XmlDocument();
    3. xmlDoc.LoadXml(xmlTextToRead.text);
    4. XmlNode node = xmlDoc.root;
    5. /// more code that ican't remember.
    6.  
    everything after that is just parsing the xml. And i've gotten these to work in a number of places both in releases and random ideas i had.

    Sorry i didn't really answer your question either >.<
     
    Last edited: Jun 28, 2012
  4. almo

    almo

    Joined:
    Jul 14, 2010
    Posts:
    83
    I had this problem, and just solved it. In Player Settings, Other Settings, if you Api Compatibility Level is .NET 2.0 subset, you will get this error. With .NET 2.0, you will not. It does make your final app bigger, though.
     
    Alvaro_Spain and lee93dong like this.