Star79
asked on
'ArrayList' is an invalid value for the XmlElementAttribute.DataType property. The property may only be specified for primitive types.
Hi,
I am stuck with a web service problem.
I need my Web service to return an xml in the following format
<?xml version="1.0" encoding="utf-8" ?>
<Employee Type="HR">
<Addresses AddressId="1">
</Addresses>
</Employee>
So class structure i would follow
XmlRoot(ElementName = "Employee"), Serializable]
public class Employee
{
[XmlAttribute(AttributeNam e = "Type", DataType = "string", Form = XmlSchemaForm.Qualified, Namespace = "")]
[EditorBrowsable(EditorBro wsableStat e.Advanced )]
public string _Type;
[XmlIgnore()]
public string Type
{
get
{
return _Type;
}
set
{
_Type = value;
}
}
}
[XmlElement(ElementName = "addresses", IsNullable = false, Form = XmlSchemaForm.Qualified, DataType = "Arraylist")]
[EditorBrowsable(EditorBro wsableStat e.Advanced )]
public Arraylist _addresses;
end class
[XmlRoot(ElementName = "Addresses"), Serializable]
public class Addresses
{
[XmlAttribute(AttributeNam e = "AddressId", DataType = "int", Form = XmlSchemaForm.Qualified, Namespace = "")]
[EditorBrowsable(EditorBro wsableStat e.Advanced )]
public int _addressId;
[XmlIgnore()]
public int AddressId
{
get
{
return _addressId;
}
set
{
_addressId = value;
}
}
}
I am trying to serilaize the above using the collections but i am getting the following error
'ArrayList' is an invalid value for the XmlElementAttribute.DataTy pe property. The property may only be specified for primitive types.
any help will be highly appreciated.
Thanks,
Rithesh
I am stuck with a web service problem.
I need my Web service to return an xml in the following format
<?xml version="1.0" encoding="utf-8" ?>
<Employee Type="HR">
<Addresses AddressId="1">
</Addresses>
</Employee>
So class structure i would follow
XmlRoot(ElementName = "Employee"), Serializable]
public class Employee
{
[XmlAttribute(AttributeNam
[EditorBrowsable(EditorBro
public string _Type;
[XmlIgnore()]
public string Type
{
get
{
return _Type;
}
set
{
_Type = value;
}
}
}
[XmlElement(ElementName = "addresses", IsNullable = false, Form = XmlSchemaForm.Qualified, DataType = "Arraylist")]
[EditorBrowsable(EditorBro
public Arraylist _addresses;
end class
[XmlRoot(ElementName = "Addresses"), Serializable]
public class Addresses
{
[XmlAttribute(AttributeNam
[EditorBrowsable(EditorBro
public int _addressId;
[XmlIgnore()]
public int AddressId
{
get
{
return _addressId;
}
set
{
_addressId = value;
}
}
}
I am trying to serilaize the above using the collections but i am getting the following error
'ArrayList' is an invalid value for the XmlElementAttribute.DataTy
any help will be highly appreciated.
Thanks,
Rithesh
I would assume that you need to fully qualify the name, and get the case correct: System.Collections.ArrayLi st, not "Arraylist".
ASKER
Sorry i tried, it doesnt work. Any other option?
I don't use XML serialization very much anymore, so I am required to think about this more closely.
I believe that you are looking for the XmlArrayAttribute
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlarrayattribute.aspx
I believe that you are looking for the XmlArrayAttribute
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlarrayattribute.aspx
public class MyRootClass
{
private Item [] items;
/* Here is a simple way to serialize the array as XML. Using the
XmlArrayAttribute, assign an element name and namespace. The
IsNullable property determines whether the element will be
generated if the field is set to a null value. If set to true,
the default, setting it to a null value will cause the XML
xsi:null attribute to be generated. */
[XmlArray(ElementName = "MyStrings",
Namespace = "http://www.cpandl.com", IsNullable = true)]
public string[] MyStringArray;
/* Here is a more complex example of applying an
XmlArrayAttribute. The Items property can contain both Item
and BookItem objects. Use the XmlArrayItemAttribute to specify
that both types can be inserted into the array. */
[XmlArrayItem(ElementName= "Item",
IsNullable=true,
Type = typeof(Item),
Namespace = "http://www.cpandl.com"),
XmlArrayItem(ElementName = "BookItem",
IsNullable = true,
Type = typeof(BookItem),
Namespace = "http://www.cohowinery.com")]
[XmlArray]
public Item []Items
{
get{return items;}
set{items = value;}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.