Use XmlSerializer to obtain an XML fragment

R

Russell

I have a class with a single public member. I use the XmlAttribute
attribute to serialize it as an attribute rather than an element.

I want to create methods to serialize and deserialize instances as XML
fragments rather than as whole documents.

When I create an XmlSerializer for the class and serialize it, I get

<?xml version="1.0" encoding="utf-16"?> <POINT
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" wkt="POINT(50.0 100.999)"
/>

when all I really want is an XML fragment without namespace details,
i.e.

<POINT wkt="POINT(50.0 100.999)" />

I'd similarly like to be able to use the XmlSerializer to deserialize
such a fragment.

I could do all this with direct string manipulation or by implementing
IXmlSerializable and my own ReadXML, WriteXML methods if I need to but
I'd like to know if there is a way to do this with the standard XML
serializers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top