Northwoods.GoWeb.Xml Assembly > Northwoods.GoWeb.Xml Namespace : GoXmlWriter Class |
XmlDocument
or just writing to an XmlWriter
.'Declaration Public Class GoXmlWriter Inherits GoXmlReaderWriterBase
public class GoXmlWriter : GoXmlReaderWriterBase
To produce XML, this class opens a XmlWriter, generates XML instructions, starts a root element, and then iterates twice over the set of Objects. The first pass (implemented by GenerateDefinitions) gives each object a chance to detect and remember shared objects and set up other definitions in preliminary XML elements that are part of the root. The second pass (implemented by GenerateObjects) actually produces elements for the Objects.
You must provide type-specific customizations by supplying instances of IGoXmlTransformer. Each transformer is associated with a Type
. As this writer processes each object that it is rendering, it searches for the appropriate transformer to invoke, starting with that type and trying its base types.
By default there are no transformers registered for this writer, so this writer is unable to actually do anything with the specified Objects. You will need to call GoXmlReaderWriterBase.AddTransformer for each class of object for which you want to produce XML. These calls to GoXmlReaderWriterBase.AddTransformer are sometimes done in an override of GoXmlReaderWriterBase.RegisterTransformers, but you probably do not need to define a class inheriting from GoXmlWriter.
For the GenerateDefinitions pass, DefineObject is called for each object in Objects, which in turn calls IGoXmlTransformer.GenerateDefinitions on the registered transformer for the object's Type
.
For the GenerateObjects pass, GenerateObject is called for each object in Objects, which in turn calls GenerateElement, GenerateAttributes, GenerateBody, and IGoXmlTransformer.GenerateElementFinish on the registered transformer for the object's Type
.
The various Invoke...
methods do the actual lookup for a transformer and invoke the respective method on the first transformer found.
public void SaveSimpleXml(String path) { GoXmlWriter xw = new GoXmlWriter(); xw.RootElementName = "graph"; xw.NodesGeneratedFirst = true; // tell the writer how to handle two kinds of classes xw.AddTransformer(new SimpleXmlTransformBasicNode()); xw.AddTransformer(new SimpleXmlTransformLink()); // specify the objects to be generated xw.Objects = myView.Document; using (StreamWriter sw = new StreamWriter(path)) { xw.Generate(sw); } }
System.Object
Northwoods.GoWeb.Xml.GoXmlReaderWriterBase
Northwoods.GoWeb.Xml.GoXmlWriter
Northwoods.GoWeb.Svg.GoSvgWriter
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2