|
.Net Integration Examples
Liquid Fast Infoset for .Net provides an intuitive API that integrates with the .Net framework XML classes. The FIReader and FIWriter classes derive from XmlReader and XmlWriter respectively and so can be seamlessly integrated within your application in place of existing .Net classes such as XmlTextReader and XmlTextWriter.
System.Xml.XmlDocument
The XmlDocument class within the .Net Framework represents an XML document implemented as a DOM tree.
These examples show how Liquid Fast Infoset for .Net easily integrates with the XmlDocument class in the same way as the .Net classes XmlTextReader and XmlTextWriter, allowing us to convert between the Xml document and Fast Infoset document formats with just a few lines of code.
Example: Convert an XML document to a Fast Infoset document
CopyC#
using System.Xml; using LiquidTechnologies.FastInfoset;
string xmlFilename = new string(@"c:\MyFile.xml");
string finfFilename = new string(@"c:\MyFile.finf");
XmlDocument doc = new XmlDocument();
using XmlTextReader
XmlReader reader = XmlReader.Create(new XmlTextReader(xmlFilename), null);
doc.Load(reader);
reader.Close();
using FIWriter
XmlWriter fiWriter = XmlWriter.Create(new FIWriter(finfFilename));
doc.WriteTo(fiWriter);
fiWriter.Close(); |
Example: Convert a Fast Infoset document to an XML document
CopyC#
using System.Xml; using LiquidTechnologies.FastInfoset;
string xmlFilename = new string(@"c:\MyFile.xml");
string finfFilename = new string(@"c:\MyFile.finf");
XmlDocument doc = new XmlDocument();
using FIReader
XmlReader fiReader = XmlReader.Create(new FIReader(finfFilename), null);
doc.Load(fiReader);
fiReader.Close();
using XmlTextWriter
XmlWriter writer = XmlWriter.Create(new XmlTextWriter(xmlFilename, Encoding.Default));
doc.WriteTo(writer);
writer.Close();
|
|