Below is a sample of some XML that I am writing. This is valid XML, but in an attempt to cut down the file size I'd like to remove the tags and simply write the value in-line with the attribute.
What I currently have
<custom-attributes>
<custom-attribute attribute-id="isDropShip">
<value>false</value>
</custom-attribute>
<custom-attribute attribute-id="restrictPayPal">
<value>false</value>
</custom-attribute>
</custom-attributes>
What I'd prefer to have
<custom-attributes>
<custom-attribute attribute-id="isDropShip">false</custom-attribute>
<custom-attribute attribute-id="restrictPayPal">false</custom-attribute>
</custom-attributes>
List holding custom attributes and extending list add method
List<sharedTypeSiteSpecificCustomAttribute> custom = new List<sharedTypeSiteSpecificCustomAttribute>();
custom.AddAttribute("isDropShip", dropship);
custom.AddAttribute("restrictPayPal", subClass);
Add method extension
public static class ListExtensions
{
public static void AddAttribute(this List<sharedTypeSiteSpecificCustomAttribute> list, string id, string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return;
}
list.Add(new sharedTypeSiteSpecificCustomAttribute { attributeid = id, value = new[] { value } });
}
}
XSD sharedTypeSiteSpecificCustomAttribute code
public partial class sharedTypeSiteSpecificCustomAttribute : sharedTypeCustomAttribute
{
private string siteidField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("site-id")]
public string siteid
{
get
{
return this.siteidField;
}
set
{
this.siteidField = value;
}
}
}
sharedTypeCustomAttribute code
public partial class sharedTypeCustomAttribute
{
private string[] valueField;
private string[] textField;
private string attributeidField;
private string langField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("value")]
public string[] value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string[] Text
{
get
{
return this.textField;
}
set
{
this.textField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("attribute-id")]
public string attributeid
{
get
{
return this.attributeidField;
}
set
{
this.attributeidField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, Namespace = "http://www.w3.org/XML/1998/namespace")]
public string lang
{
get
{
return this.langField;
}
set
{
this.langField = value;
}
}
}
Any help is appreciated. This is new to me and I'm just trying to learn the best practices and approaches.