G
Guest
I have a class that I need to serialize. For example if I had a Person class
with the properties of FirstName and LastName. Currently when I serialize the
class it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Person>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Person>
My issue is the first line (<?xml version="1.0" encoding="utf-8"?>). It
can't be included in the xml since I have to send the xml as a string to an
outside java applet. If the declaration is included it will be interpreted as
malformed by the applet. So the xml must look as follows:
<Person>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Person>
The class lookes as follows:
[XmlRoot(ElementName="Person",IsNullable=false),Serializable]
public class Person
{
public Person()
{
}
[XmlElement(ElementName="FirstName",IsNullable=false,DataType="string")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public string firstName;
[XmlIgnore]
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
[XmlElement(ElementName="LastName",IsNullable=false,DataType="string")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public string lastName;
[XmlIgnore]
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
}
Is there an attribute that i'm missing that would solve my problem? I'd
rather go the attribute route since it is an elegant solution. I don't think
string parsing is the answer.
Any ideas?
with the properties of FirstName and LastName. Currently when I serialize the
class it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Person>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Person>
My issue is the first line (<?xml version="1.0" encoding="utf-8"?>). It
can't be included in the xml since I have to send the xml as a string to an
outside java applet. If the declaration is included it will be interpreted as
malformed by the applet. So the xml must look as follows:
<Person>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Person>
The class lookes as follows:
[XmlRoot(ElementName="Person",IsNullable=false),Serializable]
public class Person
{
public Person()
{
}
[XmlElement(ElementName="FirstName",IsNullable=false,DataType="string")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public string firstName;
[XmlIgnore]
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
[XmlElement(ElementName="LastName",IsNullable=false,DataType="string")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public string lastName;
[XmlIgnore]
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
}
Is there an attribute that i'm missing that would solve my problem? I'd
rather go the attribute route since it is an elegant solution. I don't think
string parsing is the answer.
Any ideas?