• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by rain · Mar 17, 2012 at 03:02 AM · wwwxmlencoding

Accessing XML through www

Hi!

I'm looking for a quick solution to accessing an XML file through a WWW request.

My WWW request returns the text of an XML, and i'd want to use it without having it distorted(I'll explain distortion below).

     WWW www = new WWW(url);                
     while(!www.isDone)
     {            
         yield return new WaitForSeconds(0.1f);
     }
     
     string wwwtext = ASCIIEncoding.ASCII.GetString(Encoding.Convert(Encoding.UTF8,Encoding.ASCII,www.bytes));    
     
     Debug.Log("new xmldoc");        
     XmlDocument result = new XmlDocument();
     
     
     Debug.Log("loadxml");        
     try
     {
         result.LoadXml(wwwtext); 
     }
     catch{}        

     
     Debug.Log(wwwtext);    
     
     Debug.Log(result.InnerXml.ToString());
     return false;

So here, i get the xml text which can't be parsed to the XmlDocument, giving me an exception. When I print the text i get back from the WWW, it's different from the XML source, for example:

<resp stat="ok" version="2.0">

became

{"resp": {"status": true, "search":

What can I do to get the original xml source?

Thanks for the help!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by JDPennock · Mar 17, 2012 at 04:32 AM

Um, It doesn't look like the server you are trying to get xml from is giving you xml.

The format that looks like what you have: {"resp": {"status": true, "search": ect is called JSON a lot of people are using it now a days instead of XML since the files tend to be much smaller and faster to send over the internet.

If it is your own server that you are trying to get data from, try and figure out why your framework is giving you JSON and not XML.

If it is not your server or if you can't figure it out, its not a big deal either, JSON tends to be easier to work with the XML anyway you just need to find a JSON library to help you get at the data.

I would recommend litJSON, its a nice simple open source .net JSON library that works very well with unity. Just drop the dll in your project read through its docs a bit and your should be good to go.

I have a lot of experience loading both XML and JSON data into Unity, but I know relatively little of the server side aspects of it (I usually pay someone to setup the web api for me) so I will not be of much help in try to help you configure your server if that is the problem.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JDPennock · Mar 17, 2012 at 04:35 AM 0
Share

oh just to add a note, litJSON has failed on me a bit when I try to parse really huge files, but for smaller normalish sized stuff it works fine. Just thought I'd let you know.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Disable Cache for WWW 7 Answers

How to read xml file using javascript? 0 Answers

XMLSerializer Encoding Issue 2 Answers

Loading a XML file via WWW is slow, How can I make it faster? 1 Answer

Guys please help me!!how to download xml file from url in android device runtime 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges