///<summary>
/// Write the whole WordML document
///</summary>
///<param
name="wtr">The XmlTextWriter to write
to</param>
protected
void
WriteDoc(XmlTextWriter wtr)
{
// start <xml>
tag
wtr.WriteStartDocument();
// add processing
instructions
wtr.WriteProcessingInstruction("mso-application",
"progid=\"Word.Document\"");
// start
<wordDocument> tag
wtr.WriteStartElement("w", "wordDocument", WordMLNS);
// write
namespaces
foreach(string
prefix
in
_namespaces.AllKeys)
{
wtr.WriteAttributeString("xmlns", prefix,
null, _namespaces[prefix]);
}
// start <body>
tag
wtr.WriteStartElement("body", WordMLNS);
// call WritePict to
add our image to the Xml stream.
WritePict(wtr);
// end <body>
tag
wtr.WriteEndElement();
// end
<wordDocument> tag
wtr.WriteEndElement();
// end <xml>
tag
wtr.WriteEndDocument();
}
///<summary>
/// Write the Pict WordML element
///</summary>
///<param
name="wtr">The XmlTextWriter to write
to</param>
protected
void
WritePict(XmlTextWriter wtr)
{
if(_data==null)
{
return;
}
// start <pict>
tag
wtr.WriteStartElement("pict", WordMLNS);
// start
<binData> tag
wtr.WriteStartElement("binData", WordMLNS);
wtr.WriteAttributeString("name", WordMLNS,
string.Format("wordml://{0}{1}", _name,
_extension));
// write the image as
Base64
wtr.WriteBase64(_data, 0, _data.Length);
// end
<binData> tag
wtr.WriteEndElement();
// start
<shape> tag which describes the shape containing the image
wtr.WriteStartElement("shape", VMLNS);
wtr.WriteAttributeString("id", "_x0000_" + _name);
wtr.WriteAttributeString("style",
string.Format("width:{0}px;height:{1}px",
_width, _height));
// start
<imagedata> tag which links to the <binData> above.
wtr.WriteStartElement("imagedata", VMLNS);
wtr.WriteAttributeString("src",
string.Format("wordml://{0}{1}", _name,
_extension));
wtr.WriteAttributeString("title", OfficeNS, _title);
// end
<imagedata> tag
wtr.WriteEndElement();
// end <shape>
tag
wtr.WriteEndElement();
// end <pict>
tag
wtr.WriteEndElement();
}