Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

XMLNodeList

Discussion in 'Windows' started by tmanallen, Jul 23, 2013.

  1. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Hello all, Trying to convert my app to windows store apps and parse my xml and keep getting the following errors.

    The type or namespace name 'XmlDocument' could not be found (are you missing a using directive or an assembly reference?)

    The type or namespace name 'XmlNodeList' could not be found (are you missing a using directive or an assembly reference?)


    something has changed just can't seem to find the answer in google.
     
    Last edited: Jul 25, 2013
  2. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    So I was reading that we could use

    Now before what I did was just add the .dll file in a separate folder and it worked perfectly but now I keep getting this error, any ideas?
     
  3. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,939
    You have to use XDocument and friends, not XmlDocument.
     
  4. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    I just found that out, thanks Tomas.
     
  5. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Here is a question I hope someone could really answer. When ever I add the system.xml.linq to my references shut down my game and restart it disappears, why is that?
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,939
    Disappears from where?
     
  7. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    From my references like I never added it to the reference list and I have to add it everytime I start a project.
     
  8. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,939
    Which project is that?
    * the one generated by Editor when you build Windows Store Apps
    * Assembly-CSharp
     
  9. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    For the windows store app and windows phone 8 and yes Assembly-CSharp.
     
  10. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,939
    As far as I know System.Xml.Linq is included automatically, because those solutions use Microsoft compiler under the hood. So you don't need to explicilty add reference to System.Xml.Linq


    As for Assembly-CSharp, yes, you're right, it does disappear, because Unity is regenerating the project from scratch, and any modifications done to that project will be lost, System.Xml.Linq will be added by default to Assembly-CSharp in 4.3
     
  11. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Thanks for the information. You have solved alot of problems. I still have to add it because the compiler doesn't see it otherwise unless I am doing something wrong.
     
  12. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Same path new issue. So I am using xdocument to load my www url and now I am getting the

    Here is the code that I am getting it from:

    Code (csharp):
    1.  
    2.  
    3.    xmlDoc = XDocument.Load(highURL.text);
    4.            // xmlDoc =  XDocument.Parse(highURL.text);
    5.           List<HigscoreInfo> data =( from item in xmlDoc.Descendants("player")
    6.                        select new HigscoreInfo
    7.                        {
    8.                           Username  = item.Element("username").Value,
    9.                        }).ToList<HigscoreInfo>();
    10.            
    11.  
    12.  
    13.  
    Any suggestions.
     
  13. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,939
    highURL.text is invalid according to the exception
     
  14. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Wow, never thought of that but this is how unity reads www correct, have to find another route I guess, thanks for the insight.
     
  15. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Just went and fixed everything and kept it all the same going to post the answer though using XDocument and XElement.
    I am using Scoreoid's api which is a beast and here is the snippet to make everything work.


    Code (csharp):
    1.  
    2.  void OnGUI()
    3.  {
    4.      //convert our xelements to usable xml parsed data
    5.        IEnumerable<XElement> players = data.Elements();
    6.        IEnumerable<XElement> score = data.Elements();
    7.      
    8.      GUILayout.BeginArea(new Rect(150, 70, 1000, 800));
    9.    
    10.  
    11.      foreach (var player in players.Elements())
    12.      {
    13.          GUILayout.TextArea(players.Elements("player").Attributes("username").ElementAt(0).Value, style, GUILayout.Width(600));
    14.        
    15.      }
    16.    
    17.      GUILayout.EndArea();
    18.    
    19.      GUILayout.BeginArea(new Rect(650, 70, 1000, 800));
    20.  
    21.    
    22.      foreach (var scores in score.Elements())
    23.      {
    24.         GUILayout.TextArea(scores.Elements("score").Attributes("score").ElementAt(0).Value.ToString(), style, GUILayout.Width(600));
    25. }
    26.  
    27.  
    28.  
    29.  
    That should be all you would need in ONGUI to get it to look nice and pretty.