Deserialize an ArrayList

xml

    Next

  • 1. Set View Code as default VS2005 XSD editor
    Can someone tell how to set the View Code view as the default view for editing schemas in Visual Studio 2005 (instead of View Grid). (I'm afraid my Googling didn't get me even warm!) Thanks, Pete.
  • 2. Help please
    Hi Wonder if anyone can point me in the right direction, I want to automate printing cheques I have a database (sql) with four tables that hold the following info. 1. amount 2. Name 3. Address 4 . amount What I want to achieve is the following: To be able to print 10 cheques all addressed different with the right cash figure on each cheque Is this possible with xml.? cheers D

Deserialize an ArrayList

Postby sh » Fri, 04 Jul 2008 00:19:33 GMT

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?

Re: Deserialize an ArrayList

Postby Joe Fawcett » Fri, 04 Jul 2008 18:22:58 GMT






It can serialise/deserialise an ArrayList. It cannot cope with an Array of 
ArrayLists.

-- 

Joe Fawcett (MVP - XML)
 http://www.**--****.com/  


Re: Deserialize an ArrayList

Postby sh » Sat, 05 Jul 2008 00:38:10 GMT

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?







Re: Deserialize an ArrayList

Postby Joe Fawcett » Sat, 05 Jul 2008 02:03:41 GMT

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 


Similar Threads:

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

7. C++ .Net ArrayList Attribute XmlSerialization

8. Xml Serialization of ArrayLists in Managed C++



Return to xml

 

Who is online

Users browsing this forum: No registered users and 49 guest