Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have two different problems here -- an XML parsing problem and a conversion problem.</p> <p>For the binding to work, you need to parse the XML into a class that represents it's values. For the conversion issue, I point you to concept of <a href="http://msdn.microsoft.com/en-us/library/ayybcxe5.aspx" rel="nofollow noreferrer">TypeConverters</a>, which are fairly straightforward to use. For the XML parsing issue, I want to highlight LINQ-to-XML, which I think is the bees knees. A few lines of it can reconstitute even the most intricate of object graphs from an XML source. For your example of Project/Message/BitField, I've partially implemented a solution that will give you the pattern.</p> <p>Note the "LoadFromXml" method. This uses a linq-to-xml expression that populates your object graph. The one thing that this query changes in your XML source is that it expects the collection nodes (i.e. or ) to be surrounded by collection nodes (i.e. )</p> <pre><code> public class Project { public string Name { get; set; } public List&lt;Message&gt; MessageCollection = new List&lt;Message&gt;(); public void LoadFromXml(string xmlString) { // From System.Xml.Linq XDocument xDocument = XDocument.Parse(xmlString); // The following assumes your XML is well formed, is not missing attributes and has no type conversion problems. In // other words, there is (almost) zero error checking. if (xDocument.Document != null) { XElement projectElement = xDocument.Element("Project"); if (projectElement != null) { Name = projectElement.Attribute("Name") == null ? "Untitled Project" : projectElement.Attribute("Name").Value; MessageCollection = new List&lt;Message&gt; (from message in xDocument.Element("Project").Elements("Messages") select new Message() { Name = message.Attribute("Name").Value, BitfieldCollection = new List&lt;BitField&gt; (from bitField in message.Elements("Bitfields") select new BitField() {High = int.Parse(bitField.Attribute("High").Value), Low = int.Parse(bitField.Attribute("Low").Value)}) } ); } } } } public class Message { public string Name { get; set; } public List&lt;BitField&gt; BitfieldCollection = new List&lt;BitField&gt;(); } public class BitField { public int High { get; set; } public int Low { get; set; } public List&lt;string&gt; ValueCollection = new List&lt;string&gt;(); } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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