XML Serialization
Question posted by: vector
(Guest)
on
November 11th, 2005 10:50 PM
I've found that I have a use for XML serialization. Does .NET's
support for XML serialization of classes require that a new document
be created each time a class is serialized, or is there some way to
serialize the same class object repeatedly in a single XML document?
In other words, for this class:
[XmlType()]
public class MyRecord
{
[XmlElement()]
public string Name;
}
I don't want this:
MyRecord myRecord = new MyRecord();
myRecord.Name = "Foo Bar";
PerformSerialization(myRecord);
myRecord.Name = "Joe User";
PerformSerialization(myRecord);
to produce this:
<?xml version="1.0" encoding="IBM437"?>
<MyRecord xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="id1">
<Name xsi:type="xsd:string">Foo Bar</Name>
</MyRecord>
<?xml version="1.0" encoding="IBM437"?>
<MyRecord xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="id1">
<Name xsi:type="xsd:string">Joe User</Name>
</MyRecord>
I want this:
<MyRecord>
<xs:element name="Name" type="string">Foo Bar</Name>
</MyRecord>
<MyRecord>
<xs:element name="Name" type="string">Joe User</Name>
</MyRecord>
(Well, ok, what I REALLY want is this:)
<root>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyRecord">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<MyRecord>
<Name>Foo Bar</Name>
</MyRecord>
<MyRecord>
<Name>Joe User</Name>
</MyRecord>
</root>
On a related note, if I have to implement my own serialization class,
how might I implement this function:
public XmlQualifiedName ConvertTypeToXMLQualifiedName(System.Type
systemType)
{
//do stuff
}
0
Answers Posted
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 196,833 network members.
Top Community Contributors
|