I have a web service that has an input object similar to the following.
public class MyInput {[System.Xml.Serialization.XmlArrayItem ( "demographic")] public demographic information [] Demographics {get; Set;}}
With the definition of such demographic information class.
public class demographic information {[System.Xml.Serialization.XmlAttributeAttribute ()] public string name {get; Set; } Public string value {get; Set; }}
Now it generates an XML structure like this.
& lt; Demographics & gt; & Lt; Demographic name = "string" & gt; & Lt; Price & gt; String & lt; / Pricing & gt; & Lt; / Demographic & gt; & Lt; Demographic name = "string" & gt; & Lt; Price & gt; String & lt; / Pricing & gt; & Lt; / Demographic & gt; & Lt; / Demographics & gt;
I need to get it into this
& lt; Demographics & gt; & Lt; Demographic name = "string" & gt; String & lt; / Demographic & gt; & Lt; Demographic name = "string" & gt; String & lt; / Demographic & gt; & Lt; / Demographics & gt;
For my life, I am unable to find the appropriate attribute (s) to achieve this format. Does anybody have any advice?
If you want to know the structure, then the easiest option is to work back from Xml; Xml in a file ( foo.xml
type in my case), then (on the command line):
xsd foo.xml xsd foo.xsd / classes < / Code>
Then look at foo.cs
to see how it can be done; It has been detected that you [System.Xml.Serialization.XmlTextAttribute ()]
.
Here the XSD output is:
// ------------------- ---------------------------- ---------------------- --------- // & lt; Auto Generated & gt; // This code was generated by a tool // Runtime Version: 2.0.50727.3053 // // Changes made in this file may be the reason for wrong behavior and if // is reproduced then it will be lost. // & lt; / Auto-generated & gt; // ------------------------------------------------ ------------------------------ Using System.Xml.Serialization; // // This source code was generated automatically by XSD, version = 2.0.50727.3038. // /// & lt; Comment / & gt; [System.CodeDom.Compiler.GeneratedCodeAttribute ( "XSD", "2.0.50727.3038")] [System.SerializableAttribute ()] [System.Diagnostics.DebuggerStepThroughAttribute ()] [System.ComponentModel.DesignerCategoryAttribute ( "Code")] [system .Xml.Serialization.XmlTypeAttribute (AnonymousType = true)] [System.Xml.Serialization.XmlRootAttribute (namespace = "", IsNullable = false)] public partial class demographics {private demographic demographic [] items field; /// & lt; Comment / & gt; [System.Xml.Serialization.XmlElementAttribute ( "demographic" form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)] public DemographicsDemographic [] before {{get this.itemsField return; } Set {this.itemsField = value; }}} /// & lt; Comment / & gt; [System.CodeDom.Compiler.GeneratedCodeAttribute ( "XSD", "2.0.50727.3038")] [System.SerializableAttribute ()] [System.Diagnostics.DebuggerStepThroughAttribute ()] [System.ComponentModel.DesignerCategoryAttribute ( "Code")] [system .xml.Serialization.XmlTypeAttribute (anonymous type = true)] Public partial demographic demographic {Private string name field; Private string valueField; /// & lt; Comment / & gt; [System.Xml.Serialization.XmlAttributeAttribute ()] Get the public string name {get {this.nameField; } Set {this.nameField = value; }} /// & lt; Comment / & gt; [System.Xml.Serialization.XmlTextAttribute ()] Public String Value {get {return.valueField; } Set {this.valueField = value; }}}
Comments
Post a Comment