if the order is important then you need an additional property to hold that
information. I don't believe it is guaranteed in Xml Serialization.
Example:
using System;
using System.Xml.Seri alization;
namespace Sample
{
public class AppStart
{
public static void Main( string[] args )
{
MyClass myClass = new MyClass();
myClass.Fill(ne w string[] {"kilroy", "was", "here"});
XmlSerializer serializer = new XmlSerializer( typeof( MyClass )
);
serializer.Seri alize( Console.Out, myClass );
}
}
public class Tuple {
[XmlText]
public string value;
[XmlAttribute]
public int index;
public Tuple() {}
public Tuple(string _s, int _i) {
index= _i;
value= _s;
}
}
public class MyClass
{
private Tuple[] _myThings;
private int _currentIndex=0 ;
[XmlElement("Thi ng", typeof(Tuple))]
public Tuple[] MyThings
{
get{ return _myThings; }
set{ _myThings = value; }
}
public void Fill(string[] _s) {
_myThings= new Tuple[_s.Length];
for (int i=0; i< _s.Length; i++)
_myThings[i]= new Tuple(_s[i],_currentIndex+ +);
}
}
}
"Amy L." <am**@paxemail. com> wrote in message
news:c7******** *************** ***@posting.goo gle.com...
Excellent example, but it brings up one question. Is thier anyway to
put some type of identification of which index it was pulled from?
Right now the XML looks like this.
<Test>
<string>Dog</string>
<string>Cat</string>
<string>Bird</string>
</Test>
But, I would rather have it do something like this, because in my app
knowing the placement of the index would be required. But this could
be a moot point if the object is always serialized from 0..N?
<Test>
<string index="1">Dog</string>
<string index="1">Cat</string>
<string index="1">Bird</string>
</Test>
Any thoughts
Amy.
Kirby Turner <ki***@whitepea ksoftware.com> wrote in message
news:<3g******* *************** **********@4ax. com>...
Assuming you are using the XmlSerializer, your string array must be a
public property with getter and setter methods. Beyond that I do not
know of any tricks. A string array should serialize fine.
Here is a sample:
using System;
using System.Xml.Seri alization;
namespace Sample
{
public class AppStart
{
public static void Main( string[] args )
{
MyClass myClass = new MyClass();
myClass.MyStrin gs = new string[] {"kilroy", "was", "here"};
XmlSerializer serializer = new XmlSerializer( typeof( MyClass )
);
serializer.Seri alize( Console.Out, myClass );
}
}
public class MyClass
{
private string[] _myStrings;
public string[] MyStrings
{
get{ return _myStrings; }
set{ _myStrings = value; }
}
}
}
HTH
-KIRBY
--
Kirby Turner, MCSD, MCAD
www.whitepeaksoftware.com
On 6 Sep 2004 19:27:52 -0700, am**@paxemail.c om (Amy L.) wrote:
I have a class that contains a string array. However, I can't get
this object to serialize in the xml output. Is there a trick to get a
string[] to serialize?
Thanks
Amy.