x


Read STRING AS XML TO SHOW LIST

Hi, what i do is read a web page as string And read the string as xml Now i want to do a

foreach (server in servers){
 servername = server.servername.value;
}

Here the code i used to read string and convert it as xml :

WWW PlayerInfoUrl = new WWW("http://poker.hesahost.com/fb_helpers/get_servers_virtual.php");
yield return PlayerInfoUrl;
XmlReader xmlReader = new XmlTextReader(new StringReader(PlayerInfoUrl.text));

Thanks for your help ! :P

EDIT : I want to make a datagrid too, like show colloms like : servername, server id and show row with the value , and the player can click on colloms cell to order by ...

more ▼

asked Jun 24 '12 at 04:43 AM

hesa2020 gravatar image

hesa2020
48 11 13 16

Still need to find how to

Jun 24 '12 at 03:08 PM hesa2020

The XMLTextReader class is a parser of type: pull parsing while XmlDocument parses the xml as DOM.

Both are standard .NET classes. There are hundreds of examples out there. It also as been asked around 10 times here how to parse xml.

Furthermore parsing an xml string isn't really Unity specific.

Jun 25 '12 at 11:08 AM Bunny83
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

First of all really good question.

And you where trying to use , xmlTextReader, which is a stream based class, what actually you should be doing is use a class that accepts a text input as xml not a file, XmlDocument is what i know.There might be other classes also, im not sure.

the below is the sample code i have check and can assure tht it works

 WWW PlayerInfoUrl;
 XmlDocument _doc;
bool lol=false;

// Use this for initialization
void Start () {

    PlayerInfoUrl = new WWW("http://poker.hesahost.com/fb_helpers/get_servers_virtual.php");

}

// Update is called once per frame
void Update () {


    if(PlayerInfoUrl.isDone && !lol)
    {
       _doc= new XmlDocument();
       _doc.LoadXml(PlayerInfoUrl.text);
       print (PlayerInfoUrl.text);
       lol=true;
    }

}

PS: XmlDocument class works on android and iphone also...

More info: to display it like a list of servers, first you have to decode the xml and get a string list for that look into xmlNodeList the snippet for fetching is

XmlNodeList _list = _doc.SelectNodes("servers/server");

after fetching and saving it in a global variable display it from on gui. I hope this is clear??!

       foreach(XmlNode _node in _list)
       {
         if(GUILayout.Button(_node.Attributes.GetNamedItem("myAttribute").Value))
         {
          //join the server
         }
       }
more ▼

answered Jun 24 '12 at 08:17 PM

flamy gravatar image

flamy
3.5k 5 11 37

You might also want to take a look at the Lightweight XML parser since if you use the System.XML namespace it will increase your build size by around 1 MB.

Jun 25 '12 at 11:15 AM Bunny83

oh! looks intresting, ill take a look into it. Thanks

Jun 25 '12 at 12:01 PM flamy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x354
x255
x78
x55
x36

asked: Jun 24 '12 at 04:43 AM

Seen: 702 times

Last Updated: Jun 25 '12 at 12:01 PM