Search Unity

XML Parser in C#

Discussion in 'Scripting' started by wgrand, Apr 5, 2010.

  1. wgrand

    wgrand

    Guest

    Joined:
    Mar 11, 2010
    Posts:
    14
    Anyone aware of a simple XML parser in C#? (Not Javascript!)

    I am trying to avoid System.Xml, which will add 1mb to my file size.

    I also wish there was an easy parser like E4X in Actionscript!
     
  2. Flashflow

    Flashflow

    Joined:
    Mar 25, 2010
    Posts:
    7
    I could be wrong but I'm almost certain nobody has wrote a C# XML parser for Unity yet (because we have System.Xml). I have to agree with you though that an extra MB just for XML parsing on a game is pretty crappy for the web, so might I suggest using TinyXmlReader (which is Java based) and have your C# script send and receive data from the Java class using targetObject.SendMessage(functionName, value)

    EDIT

    Oh and just as a general rule, if the script you're looking for isn't on this site, then it either probably doesn't exist or it does but is so inefficient or poorly programmed that it shouldn't be used. Generally. There are a few amazing classes and libraries outside that site, but typically if it's good it's up there.
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    best chances to find one (I think there is one) is the iphone board, as unity iphone basic users can't use System.Xml before iphone 1.7 due to static lib size restrictions of the iphone sdk and the resulting size of including system.xml (which is not just system.xml but also the inclusion of System, which makes most of that size)
     
  4. matthewminer

    matthewminer

    Joined:
    Aug 29, 2005
    Posts:
    320
    I realize that you're looking for a C# script, but it's worth mentioning the lightweight (7 KB) XML parser that a forum member wrote. You should have no problem mixing it in with your own scripts. If it's really necessary, converting the few hundred lines to C# shouldn't pose much difficulty if you're comfortable with the language.
     
  5. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,494
    Converting my TinyXmlReader into C# should be trivial, the meat of it is all just a bunch of string functions.

    EDIT: I happen to have converted the TinyXmlReader into C# myself. Just check the wiki page
     
  6. Jehu

    Jehu

    Joined:
    Aug 19, 2010
    Posts:
    16
    I have converted the lightweight (7 KB) XML parser from Javascript into C#.

    The reason I did this is so it is faster, but mainly because I could not get it to work on the iPhone as it used a Boo script data type. Even with changing that it still did not work on the iPhone.

    But after converting it to C# it now works fine on the iPhone.

    I have attached the zipped source code files (3 C# files) as a zip file.

    Hope this helps.
     

    Attached Files:

  7. riadsala

    riadsala

    Joined:
    Feb 10, 2010
    Posts:
    15
    Hello,

    dumb question here (I'm still getting my head around OOP, very different from the type of programming I'm used to).

    How do I go about using the xmlparser in a project? Do I attach the script to an otherwise empty GameObject?

    Thanks
     
  8. riadsala

    riadsala

    Joined:
    Feb 10, 2010
    Posts:
    15
    Don't worry, I've figured it out. You just stick the file in assets, and there's no need to attach it to anything.

    :)
     
  9. deepak

    deepak

    Joined:
    Aug 10, 2010
    Posts:
    44
    Hi

    I am building an application where i want to load data thro XML in the assets folder. When i build an standalone application, I am not getting the xml in the build. Its working fine in Editor. Any Suggestions?
     
  10. tingham

    tingham

    Joined:
    Nov 1, 2007
    Posts:
    18
    Seems likely that the path to the xml file has changed.
     
  11. UniversalChairs

    UniversalChairs

    Joined:
    Nov 15, 2014
    Posts:
    2
    I'm trying to simply pull headline text from an XML RSS feed to display on a 3D text element, but I can't seem to wrap my head around how to use this. I've done some intermediate C# scripting so far, I can display the raw text of a website, but I'm really struggling to figure out how to implement the parser in my code.