Note that there are some explanatory texts on larger screens.

plurals
  1. POHow load a XML from a URL in C# console program and get content into variables
    primarykey
    data
    text
    <p>----- <strong>UPDATED</strong> -----</p> <p>I have a question, simple for the more experts in c# (I am a Java dissident) and I will apreciate your help to do a good thing here using the right technique and technologies.</p> <p><strong>What I need</strong></p> <p>Load a XML file from a URL. After this I need navigate between the information sets getting the data and put it into some variables.</p> <p>This will be a .NET C# executable program , stand alone that other program in COBOL will run and recuperate the data.</p> <p>The exemple XML is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;movie&gt; &lt;title&gt; Fast Five &lt;/title&gt; &lt;year&gt; 2011 &lt;/year&gt; &lt;description&gt; Dominic Toretto and his crew of street racers plan a massive heist ... &lt;/description&gt; &lt;director&gt; &lt;director_1&gt;Justin Lin&lt;/director_1&gt; &lt;director_2&gt;Vovó Mafalda&lt;/director_2&gt; &lt;/director&gt; &lt;/movie&gt; </code></pre> <p>Accessible in, localhost:8080\movie.xml, for example.</p> <p>I have a code to load a XML:</p> <pre><code>namespace main { public class XMLLoader { public static void getXMLContent() { String title = null; String year = null; String description = null; String director1 = null; String director2 = null; String director3 = null; try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("http://localhost:8081/xml/movies.xml"); title = (xmlDoc.GetElementsByTagName("title")[0]).InnerText.Trim(); year = (xmlDoc.GetElementsByTagName("year")[0]).InnerText.Trim(); description = (xmlDoc.GetElementsByTagName("description")[0]).InnerText.Trim(); director1 = (xmlDoc.GetElementsByTagName("director_1")[0]).InnerText.Trim(); director2 = (xmlDoc.GetElementsByTagName("director_2")[0]).InnerText.Trim(); director3 = (xmlDoc.GetElementsByTagName("director_3")[0]).InnerText.Trim(); Console.WriteLine("Movie......: " + title); Console.WriteLine("Year.......: " + year); Console.WriteLine("Description: " + description); Console.WriteLine("Director1..: " + director1); Console.WriteLine("Director2..: " + director2); Console.WriteLine("Director3..: " + director3); } catch (Exception e) { Console.WriteLine(" Error to load URL"); Console.WriteLine(" Message: " + e.Message); } } static void Main(string[] args) { getXMLContent(); Console.ReadKey(); } } } </code></pre> <p>But this smells bad for me.</p> <p>There is a more efficient and beautiful way to do it? And how to load a XML from a URL in a console C# program?</p> <p>Thanks for all help and attention.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload