Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use [XmlElement] attribute on array or List properties and XmlSerializer is smart enough to pick up on that and list them in your xml one after another.</p> <p><strong>OR</strong></p> <p>You can use Visual Studio XML-to-class generator for more complicated structures: - click start menu in Windows - click "All Programs" - find Microsoft Visual Studio folder and click on it - click Visual Studio Tools folder - click Developer Command Prompt... - let's say your xml is saved in C:\test\Sample.xml - type "xsd C:\test\Sample.xml /out:C:\test" this should inform you a schema was created. - type "xsd C:\test\Sample.xsd /c /out:C:\test" this should inform you a .cs class was created for you, copy it in your solution, possibly with namespace change (or use xsd command parameter for it) - the classes created may be oddly named and more difficult to work with, use this approach if you have a complicated XML or schema. - you can extend the generated code with partial classes (look it up), don't modify the generated code directly</p> <p>--</p> <p>Here's what direct code (not generated) would look like:</p> <pre><code>public class Product{ [XmlElement] public Cycle Cycle {get;set;} [XmlElement] public Brand Brand {get;set;} [XmlElement] public Updates Updates {get;set;} } public class Updates{ [XmlElement("Item")] public UpdateItem[] Items{get;set;} } public class UpdateItem{ [XmlAttribute] public string Name{get;set;} // use [XmlAttribute] in Cycle, Brand and Artifact classes [XmlElement("Artifact")] public Artifact[] Artifact{get;set;} } //.... etc </code></pre> <p>and here's what the generated code looks like:</p> <pre><code>/// &lt;remarks/&gt; [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)] public partial class ProductUpdatesItem { private ProductUpdatesItemArtifact[] artifactField; private string nameField; /// &lt;remarks/&gt; [System.Xml.Serialization.XmlElementAttribute("Artifact", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public ProductUpdatesItemArtifact[] Artifact { get { return this.artifactField; } set { this.artifactField = value; } } </code></pre> <p>[/code]</p>
 

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