// Public Methods
#region CreateMasterContents(string styleFilePath, ArrayList odtFiles)
public void CreateMasterContents(string styleFilePath, ArrayList odtFiles)
{
var doc = new XmlDocument();
doc.Load(styleFilePath);
var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
nsmgr.AddNamespace("text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
nsmgr.AddNamespace("xlink", "http://www.w3.org/1999/xlink");
// if new stylename exists
XmlElement root = doc.DocumentElement;
string style = "//office:text";
if (root != null)
{
XmlNode node = root.SelectSingleNode(style, nsmgr); // work
if (node != null)
{
for (int i = 0; i < odtFiles.Count; i++) // ODM - ODT
{
string outputFile = odtFiles[i].ToString();
outputFile = Path.ChangeExtension(outputFile, "odt");
XmlNode newNode;
newNode = doc.CreateNode("element", "text:section", nsmgr.LookupNamespace("text"));
//attribute
XmlAttribute xmlAttrib = doc.CreateAttribute("text:style-name", nsmgr.LookupNamespace("text"));
xmlAttrib.Value = "SectODM";
newNode.Attributes.Append(xmlAttrib);
xmlAttrib = doc.CreateAttribute("text:name", nsmgr.LookupNamespace("text"));
xmlAttrib.Value = outputFile;
newNode.Attributes.Append(xmlAttrib);
xmlAttrib = doc.CreateAttribute("text:protected", nsmgr.LookupNamespace("text"));
xmlAttrib.Value = "false";
newNode.Attributes.Append(xmlAttrib);
XmlNode newNode1 = doc.CreateNode("element", "text:section-source", nsmgr.LookupNamespace("text"));
//attribute
XmlAttribute xmlAttrib1 = doc.CreateAttribute("xlink:href", nsmgr.LookupNamespace("xlink"));
xmlAttrib1.Value = "../" + outputFile;
newNode1.Attributes.Append(xmlAttrib1);
xmlAttrib1 = doc.CreateAttribute("text:filter-name", nsmgr.LookupNamespace("text"));
xmlAttrib1.Value = "writer8";
newNode1.Attributes.Append(xmlAttrib1);
newNode.AppendChild(newNode1);
node.AppendChild(newNode);
}
}
}
doc.Save(styleFilePath);
}