- Home /
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 ...
The X$$anonymous$$LTextReader class is a parser of type: pull parsing while XmlDocument parses the xml as DO$$anonymous$$.
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.
Answer by flamy · Jun 24, 2012 at 08:17 PM
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
}
}
You might also want to take a look at the Lightweight X$$anonymous$$L parser since if you use the System.X$$anonymous$$L
namespace it will increase your build size by around 1 $$anonymous$$B.
Hello, I am from 2019 and XmlDocument doesn't work on Android... I am wondering how do you declare a path within a jar file in Android? I used tons of options and none worked. I start to feel crazy. This is what i used the last time:
xml_path = "jar:file//" + Application.dataPath + "!/" + "file.xml";
Please help, if you know. Thanks!
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
using xml, linq, and lists 0 Answers
New to XML in C#, can't get anything to work. 1 Answer
Xml Serialization? (how to read/write?) 1 Answer
Write and Read to a iOS device! Help 1 Answer