I'm trying to add an XmlElement to XmlElement[] but this seems to be impossible.
the errormessage:
Cannot implicitly convert type 'System.Xml.XmlElement' to 'System.Xml.XmlElement[]'
The XmlElement[] object does not have an Add or Insert function
so how can I do this?
Update with code:
This part is created from an XSD private System.Xml.XmlElement[] anyField;
/// <remarks/>
[System.Xml.Serialization.XmlAnyElementAttribute()]
public System.Xml.XmlElement[] Any
{
get
{
return this.anyField;
}
set
{
this.anyField = value;
}
}
Here I am trying to create the object and add a UniversalShipment to the Any collection.
UniversalInterchangeBody body = new UniversalInterchangeBody();
UniversalShipmentData shipmentData = new UniversalShipmentData();
XmlElement universalShipmentXML = SerializeToXmlElement(shipmentData);
body.Any = universalShipmentXML;
public static XmlElement SerializeToXmlElement(object o)
{
XmlDocument doc = new XmlDocument();
using (XmlWriter writer = doc.CreateNavigator().AppendChild())
{
new XmlSerializer(o.GetType()).Serialize(writer, o);
}
return doc.DocumentElement;
}