C# - Array from XML as an embedded resource -
I use an array to try to find a nice clean way to load the contents of an XML file I am, but I have only partial answers here and there. My XML file is an embedded resource for simplicity, and it has a list of 115 elements, all of which have a The XML looks like this: I am able to load everything and I see my data in InnerXML, but I did not know how to use it correctly. This is the code that will ideally set this array to use for me, although it is quite broken due to me trying different things, but I It seems that it tells the general idea. Hopefully someone can understand something about it and explain to me what I'm doing (& gt ;.) I would be happy to provide more information, clarification etc. If I miss something important Used to be! Thank you! Use an xpath. id and
name attribute.
& lt ;? Xml version = "1.0" encoding = "UTF-8" standalone = "yes"? & Gt; & Lt; Item xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" & gt; & Lt; Item & gt; & Lt; ID & gt; 1 & lt; / Id & gt; & Lt; Name & gt; Example1 & lt; / Name & gt; & Lt; / Item & gt; & Lt; Item & gt; & Lt; ID & gt; 2 & lt; / Id & gt; & Lt; Name & gt; Example2 & lt; / Name & gt; & Lt; / Item & gt; & Lt; Item & gt; & Lt; ID & gt; 3 & lt; / Id & gt; & Lt; Name & gt; Example3 & lt; / Name & gt; & Lt; / Item & gt; & Lt; / Item & gt;
Public Form 1 () {InitializeComponent (); Assembly = assembly Gate contingency assembly (); XmlDocument xml = Faucet; Try {string filePath = "MyProject.ItemList.xml"; Stream file = stream assembly. Gate Expedition Assembly () GetManifestResourceStream (filePath); If (filestream! = Null) {xml = New XmlDocument (); Xml.Load (FileStream); }} Hold {// nothing} XmlDocument itemsFromXML = xml.DocumentElement.InnerXml; Forex currency (XMLNode node in items) {int id = convert toInt32 (node properties.gate named item ("id"). Toasting ()); String name = node. Features. Gitanamideum ("name"). ToString (); GameImemist.Add (new game item (id, name)); }}
XmlNodeList nodes = xml.SelectNodes ("Items / Items"); Forresh (XMLNode node in nodes) {int id = int.Parse (node. SelectionSinlingNode ("id"). }
Comments
Post a Comment