Read single attribute from Xml and assign it to a variable.

This will sound like a very basic question, but i have very few experience with programming and even less experience with xml.
All the information I have found is overly complex as it runs trought every single node of the xml files and is somewhat related to serialization.
I just want to be able to read the value of a single attribute (int) and assing it to a previously declared variable.

  • The xml file is loaded from a web server.
  • The atribute resides inside the “weatherCode” and should be assigned to the variable weatherCode.

alt text

My current code looks like this:

alt text

Thanks in advance.

Hi I’m the author of the XML-JSON Serialization package on the Asset Store.

With this package I would do it this way:

int weatherCode;

// Let's read the xmlString received from the server

XMLInStream stream = new XMLInStream(xmlString);

stream.Start("current_condition")
              .Content("weatherCode", out weatherCode)
          .End();

// Now weatherCode is assigned !

Hi

The problem is that the value you are looking for is a nested value so you atleast have to navigate to the node that you need, you could use Xpath to navigate to that exact node but i would recommend just looping over it till you find the node you need and then break as the amount of code needed is not much more and it performs better, also this way it’s easy to modify if you should need to extract more values in a future version

sorry for the wait, This code runs
you will have to test with the real xml feed yourself