Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 TehWut · Aug 01, 2012 at 10:53 PM · wwwstringxml

getting certain strings from WWW.text? (scoreoid)

Hello all, I am using an open web api known as Scoreoid

in order to implement high score funcionality. I can use the getScore() function to return what appears to be the contents of an XML file. As far as I know, all the stored data uses XML on a server, but I'm not too good in networking of any sort.

Anyways, I can use WWW.text to get the contents of the returned..page? Here is what is returned

     request completed!: <?xml version="1.0" encoding="UTF-8" ?><scores><player username="teh" email="" first_name="" last_name="" platform=""><score score="9989" created="2012-08-01 23:41:05" difficulty="0" platform="" /></player><player username="teh" email="" first_name="" last_name="" platform=""><score score="9989" created="2012-07-30 01:04:01" difficulty="0" platform="" /></player><player username="teh" email="" first_name="" last_name="" platform=""><score score="9989" created="2012-07-30 01:03:22" difficulty="0" platform="" /></player><player username="teh" email="" first_name="" last_name="" platform=""><score score="9989" created="2012-07-29 21:03:40" difficulty="0" platform="" /></player><player username="teh" email="" first_name="" last_name="" platform=""><score score="9989" created="2012-07-29 19:20:43" difficulty="0" platform="" /></player></scores>
 UnityEngine.Debug:Log(Object)
 $:MoveNext() (at Assets/Scripts/Chat.js:47)


This is nice, but how can I grab for example, the name of the user who submitted a score? I can't exactly use any XML parsing techniques, as all I have is the text data.

I could be overthinking all this. But here is the full code if necessary.

 function Start () {
 
 /* API  method */ 
 var url = "https://www.scoreoid.com/api/createScore";
 var url2 = "https://www.scoreoid.com/api/getScores";
 /* Unity WWW Class used for HTTP Request */ 
 var form = new WWWForm();
 
 form.AddField( "api_key", "string_edited_for_security" );
 form.AddField( "game_id", "string_edited");
 form.AddField( "response", "xml");
 form.AddField( "username", "teh");
 form.AddField( "score", "9989");
 
 var www = new WWW( url, form );
 
 /* Wait for request to complete */
 yield www;
 
 /* Check for errors */
 if (www.error == null)
 {
     /* Request completed! */
      Debug.Log("request completed!: " + www.text);
 } else {
     /* Something wrong! */
     Debug.Log("WWW Error: "+ www.error);
  }
  
  
  
  var form2 = new WWWForm();
 
 form2.AddField( "api_key", "edited_string" );
 form2.AddField( "game_id", "edit_string");
 form2.AddField( "response", "xml");
 
 var www2 = new WWW( url2, form2 );
 
 /* Wait for request to complete */
 yield www2;
 
 /* Check for errors */
 if (www2.error == null)
 {
     /* Request completed! */
      Debug.Log("request completed!: " + www2.text);
 } else {
     /* Something wrong! */
     Debug.Log("WWW Error: "+ www2.error);
  }
  
 }

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by rutter · Aug 01, 2012 at 11:36 PM

I'm not familiar with the specific API you're using, but you should probably try using some of .NET's built-in XML parsers.

Some helpful threads to start from:

  • http://forum.unity3d.com/threads/25352-Loading-an-XML-file

  • http://answers.unity3d.com/questions/63728/easy-xml-parsing.html

You can try to do the parsing, yourself, by checking for substrings, writing regular expressions, and so on, but it's usually not the best idea.

Comment
Add comment · 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
1

Answer by DaveA · Aug 01, 2012 at 11:49 PM

You could use XML parsing, like:

 xml = new XmlDocument();
 xml.LoadXml(www.text);
 XmlNode plyrNode = xml.FirstChild; // gets 'player' node
 string fname = plyrNode.Attributes["first_name"].Value;

But the overhead of including and using an XML parser might be overkill.

You could just use standard string methods to dig the info out of the string. Smaller faster code (but may become a burden if you have large data sets)

There's probabaly a RegEx that would parse things out for you, I'm not sure.

Comment
Add comment · 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
1

Answer by loihb · Aug 01, 2012 at 11:52 PM

Save - load script settings from xml

Download :

https://docs.google.com/open?id=0B0aMXRZ2PWXZQjhKMXdDLVJLZDA

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

www.data and string conversion to integer 2 Answers

How to convert a string to a type WWW 0 Answers

Sending cookie to XML-RPC protocol 0 Answers

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

Converting String Array to Int. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges