C# newbie: reading repetitive XML to memory -


I'm new to C # I am creating an application that creates an XML file with a list of elements Used to be. The structure of my XML file is as follows:

  & lt; Element & gt; & Lt; Element & gt; & Lt; Name & gt; Price & lt; / Name & gt; & Lt; Type & gt; Price & lt; / Type & gt; & Lt; Color & gt; Price & lt; / Color & gt; & Lt; / Element & gt; & Lt; Element & gt; & Lt; Name & gt; Price & lt; / Name & gt; & Lt; Type & gt; Price & lt; / Type & gt; & Lt; Color & gt; Price & lt; / Color & gt; & Lt; / Element & gt; & Lt; Element & gt; & Lt; Name & gt; Price & lt; / Name & gt; & Lt; Type & gt; Price & lt; / Type & gt; & Lt; Color & gt; Price & lt; / Color & gt; & Lt; / Element & gt; & Lt; / Elements & gt;  

I have & lt; Those 100 items, and this is a single list (so I'm considering overquill on DB solution, even SQLite). When my application loads, I want to read the list of elements in memory. Currently, after browsing the web a bit, I'm using XmlTextReader.

However, and perhaps I am using it incorrectly, I read the data tag-by-tag, and thus expect that the tags are in fixed order (otherwise the code will be messy) . What I would like to do is read "Element" structures and remove the tags from them by name. I'm sure this is possible, but how?

To clarify, the main difference is that the way I am using XmlTextReader today is not tolerant for the circumstances such as the wrong sequence of tags (for example the type comes first Name in a certain element)

The special reason is that you are not using XmlDocument ?

  XmlDocument myDoc = New XmlDocument () myDoc.Load (fileName); MyHD (Element / Element ") in forehack (xml aliment AMM) {XmlNode nodeName = elem.SelectSingleNode (" name / text () "); XmlNode node type = elem.SelectSingleNode ("type / text ()"); XMLNode nodecroller = elem.SelectSingleNode ("color / text ()"); String name = nodename! = Null? NodeName.Value: String.Empty; String type = node type! = Null? Nodetype Value: string.api; String color = node collar! = Null? Node color. Value: string.api; // Here you use values ​​for some ...}  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -