I have a Web Service which returns an ArrayList. According to http://www.**--****.com/ Deserialize won't work on an ArrayList. Any suggestions how to get around this?
I have a Web Service which returns an ArrayList. According to http://www.**--****.com/ Deserialize won't work on an ArrayList. Any suggestions how to get around this?
It can serialise/deserialise an ArrayList. It cannot cope with an Array of ArrayLists. -- Joe Fawcett (MVP - XML) http://www.**--****.com/
It can't cope with the following. Is this an Array of ArrayLists? <?xml version="1.0" encoding="utf-8" ?> <ArrayOfOrder xmlns:xsi=" http://www.**--****.com/ " xmlns:xsd=" http://www.**--****.com/ " xmlns=" http://www.**--****.com/ "> <Order> <OrderNo>505913</OrderNo> <Carrier>WC</Carrier> <Rush>false</Rush> <Pack>true</Pack> </Order> <Order> <OrderNo>505983</OrderNo> <Carrier>PIT</Carrier> <Rush>false</Rush> <Pack>true</Pack> </Order> <Order> <OrderNo>506017</OrderNo> <Carrier>NEP</Carrier> <Rush>false</Rush> <Pack>true</Pack> </Order> </ArrayOfOrder> If it is, is there a way around it?
No, and I have certainly coded similar serialisations. For example I have a user class that contains an ArrayList of Address objects. You just need to use the correct attributes on the members. I will go and dig out the code. -- Joe Fawcett (MVP - XML) http://www.**--****.com/ I
1.Deserialize XML into ArrayList
I am trying to take an XML snipit like the following: <project> <stuff1/> <stuff2/> </project> <project> <stuff1/> <stuff2/> </project> <project> <stuff1/> <stuff2/> </project> And deserialize it into a simple ArrayList. I would prefer to do this without a special class to deserialize into, I do have the "project" class setup. I would also prefer to not wrap these items in a root node, but can easily do that, and have tried. Here is my best attempt so far: XmlSerializer xs = new XmlSerializer( typeof( project) ); ArrayList projects = new ArrayList(); XmlDocument pxml = new XmlDocument(); pxml.LoadXml(inputXml); foreach (XmlNode project in pxml.ChildNodes) { if (!(project is XmlElement)) { continue; } projects.Add(xs.Deserialize(new XmlNodeReader(project))); } In most of my attepts I get the following error: <project xmlns="> was not expected Thanks, Richard
2.Problem deserializing ArrayList.
I have a wierd one that I hope somebody can help with. I'm trying to serialize an ArrayList of items. I am successfully serializing other ArrayLists of strings, but for some reason this code will serialize *out* the CommentLines property, but the XmlSerializer seems to ignore them when serializing them back in. Here is my code: [Serializable] public class PatchArchiveStats { ArrayList m_arrDiffItems = new ArrayList(); [XmlArrayItem( "DiffItem", typeof(DiffItem) )] public ArrayList DiffItems { get { return m_arrDiffItems; } set { m_arrDiffItems = value; } } } [Serializable] public class DiffItem { string m_strComment; // A multi-line comment. [XmlArray("CommentLines")] [XmlArrayItem( "CommentLine", typeof(string) )] public ArrayList CommentLines { get { ArrayList lines = new ArrayList(); if ( m_strComment != null ) { string strLine = null; StringReader reader = new StringReader( m_strComment ); while ( (strLine = reader.ReadLine()) != null ) { lines.Add( strLine ); } } return lines; } set { m_strComment = null; foreach ( string strLine in value ) { if ( strLine == null ) { continue; } if ( m_strComment == null ) { m_strComment = strLine; } else { m_strComment += "\n" + strLine; } } } } } Any help would be very much appreciated!
3.XML serialization of ArrayList of ArrayLists
let's suppose I have a class A. now I want to serialize an ArrayList of ArrayLists of A class objects.. what XML tags ([XmlAttribute] / [XmlElement]) do I need to add to these classes in order to be able to serialize it?
4.XML deserialize Stream works ok but deserialize from XmlNodeReader fails
5.ArrayList XmlSerialization Question
I have the following a class with ArrayList member [XmlInclude(typeof(keyword))] public class Info { Info(){data = new ArrayList();} public ArrayList keyword; public void Add(string sData) { keyword key; key = new keyword(); key.data = sData; data.Add(key); } public string SerializeObject(object oClassObject,System.Type oClassType) { XmlSerializer oSerializer = new XmlSerializer(oClassType); System.Text.StringBuilder strBuilder = new System.Text.StringBuilder(); System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder); oSerializer.Serialize(writer,oClassObject); return strBuilder.ToString(); } in my aspx page i called Info oInfo = new Info(); oInfo.Add( "Key1 "); oInfo.Add( "Key2 "); string str = oInfo.SerializeObject(oInfo,typeof(Info)); after XML Generation in the keyword section i got like this - <keyword> - <anyType xsi:type="keyword"> <LangString>key1</LangString> </anyType> - <anyType xsi:type="keyword"> <LangString>key2</LangString> </anyType> </keyword> how can I get result like following <keyword> <LangString>key1</LangString> </keyword> <keyword> <LangString>key2</LangString> </keyword> each keyword in independent element, is this possible
6. loading XML data into an ArrayList
Users browsing this forum: No registered users and 49 guest