Read xml file asp.net vb




















The file however contains all the data in similar tags like this:. As you can see, I have to enter a forecast, go through its children, find the data, and then somehow get back to the point when I can read the next forecast and its data and so on. I'm currently using XMLTextReader to be able to read, and the ReadStartElement and ReadToNextSibling methods to navigate through the file, but using those methods you cannot get back up in the file, you can only get down and in, so in order to read the next temperature I had to use a For loop that makes the program go to the next forecast 'succesfully', but it's become very resource intensive, making way too many calls to the weather API, and even giving out timeout errors.

It does work if I save the XML file from the website to the project's directory on my computer, that way it's able to run fine and get all the data quick, however, I will not be able to be saving the XML files once I upload this website to the server.

So my question is, how can I extract just the data I need from this online weather XML file, and either display it or save it to a database easily and fast? There are several ways to do this. The simplest would be to continue loading the XML the way you already are, using the XMLTextReader, but instead of only loading one at a time, load all of them at once into memory.

For instance, if you created a class like this:. Then, in your code where you load the forecasts, load all of them, instead of just one, and store them in a list like this:. Then, later, when you need a specific forecast, you can just retrieve it from the already loaded list in memory:. For instance, you could easily load all the forecasts into a list as I just described by using the XmlDocument class like this:.

Have you tried using a dataset. ReadXml method. This makes reading the data back very easy if you are familiar with a dataset structure. It will put your data in to datatables for you to be able to loop through. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. NET Ask Question. Asked 9 years, 4 months ago. Hi I am new to asp. I want read the following Xml file and store the values in variables in order to add to some other functions. It might be a simple one but please help. Thank you very much for response.

I just have one more doubt. Use SelectSingleNode. But, if you want a easy to understand approach, you can do this way If the xml data has more than one element, I would recommend using XmlSerializer to parse data. The content you requested has been removed. Ask a question. Quick access. Search related threads. ReadFrom method. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info.

Contents Exit focus mode. Is this page helpful? Please rate your experience Yes No.



0コメント

  • 1000 / 1000