information on IXmlSerializable interface

  • Thread starter Thread starter sachy
  • Start date Start date
S

sachy

Hello All,
I want to deserialize part of xml into a object. For this i am
having class that implements the IXmlSerializable interface. For this
class i get the xmlnode object that has the xml.

How do i read this xmlnode object in the readxml of
IXmlSerializable ? as the ReadXml has the xmlreader object as as
input. How do i associate the xmlreader to xmlnode so that i can go
ahead with reader.read().

Any help would be highly appreciated.

Thanks & Regards,
Sachin naik.
 
Hi,

If your goal is to feed an XmlNode into an XmlReader you may be able to
do this using the code below:

using System.IO;
using System.Text;
using System.Xml;

....

XmlNode node = GetNodeFromSomewhere();

using(MemoryStream ms = new MemoryStream())
{
byte[] nodeData = Encoding.Default.GetBytes(node.OuterXml);
ms.Write(nodeData);

using(XmlReader xr = XmlReader.Create(ms))
{
// Do something with the reader.
}
}

I haven't tested this for Xml serialization so I cannot guarantee this
will work for you.
 
Can you clarify your intent? The most efficient way to handle xml is
directly via the reader/writer, as you don't need to fill an entire
DOM (such as XmlDocument) - however, I appreciate that this isn't
always the most convenient. If you simply want to treat the reader as
a DOM, then perhaps create an XmlDocument and Load() from the reader.
This is fine for most xml - but gets painful for very large xml.

Marc
 
Back
Top