Skip to content

AnnoMods.BBDom: Basics

taubenangriff edited this page Mar 13, 2024 · 2 revisions

Default IO

Loading

using var inStream = new MemoryStream(); 
var doc = BBDocument.LoadStream(inStream);

Writing

BBDocument doc; 
using var outStream = new MemoryStream(); 
doc.WriteToStream(outStream);

V3 is used as the default version.

To use a custom version for writing, use:

doc.WriteToStream(outStream, BBDocumentVersion.V3);

Creating Documents from scratch

BBDocument doc; 

//create Nodes
var tag = doc.CreateTag("MyNodeName");
var attrib1 = doc.CreateAttrib("MyAttribName");
var attrib2 = doc.CreateAttrib("MyAttribWithContent", 53);
var stringAttrib = doc.CreateAttrib("MyStringAttribName", "Content", Encoding.UTF8);

//create Node Structure
tag.AddChildren(attrib1, attrib2, stringAttrib);
doc.AddRoot(tag);

Serialization

For serialization to a stream, you do

BBDocument doc; 
MyType obj; 
BBConvert.SerializeObject(obj, new BBSerializerOptions(), new MemoryStream());

If you wish to instead serialize to a BBDocument, you can do the following:

BBDocument doc; 
MyType obj; 
BBConvert.SerializeObjectToDocument(obj, new BBSerializerOptions());

Xml <-> BBDocument

BBDocument doc; 
XmlDocument xmlDoc = doc.ToXmlDocument(); 
XmlDocument doc; 
BBDocument bbDoc = doc.ToBBDocument(); 

Clone this wiki locally