xml - C# XmlReader, sequence problems -


It is probably quite idle, but I have a problem that is lightweight enough to be easier. This is my XML:

  & lt; Custom Fielded Options & gt; & Lt; Data type & gt; Text & lt; / Data type & gt; & Lt; Options & gt; & Lt; Option key = "Advocate" & gt; Category_Advocate & lt; / Options & gt; & Lt; Option key = "architecture- and enginewiviccomputer" & gt; Category_crumbs & lt; / Options & gt; & Lt; Option key = "Bank & Finance" & gt; Category_bank & lt; / Options & gt; & Lt; / Options & gt;  

I am trying to get a node value and main attribute in the list, such as:

 using  (XmlReader Reader = XmlReader.Create (New StringReader (xml)) {While (reader.Read ()) {reader.ReadToFollowing ("Options"); Key = reader.ReadInnerXml (); Reader.MoveToFirstAttribute (); Value = reader.Value; If (key.Length & gt; 0 & amp; amp; value.Length & gt; 0) categoryList.Add (key, value); }}  

So, for the first option, I should get a key-value of "Category_Avcator", "Advocate">

, but if I add it to the list, I have Mixed values ​​of current / previous lines are where I am getting wrong?

Thx in advance!

/ snedker

You XML from LINQ You can use:

  var xmlDocument = XDocument.Load ("Path"); Var option = xmlDocument.Descendants ("Options") .Ooxizer (x => (string) x, x = & gt; (string) x. Attribute ("key"));  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -