SourceCode/PROMS/fmtxml/EntireFormat.cs
John 8284c66da2 added code to put a copyright notice in each format file
added code to put a copyright notice in each genmac file
2012-10-25 18:48:42 +00:00

77 lines
2.7 KiB
C#

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace fmtxml
{
class EntireFormat
{
private string MyPath;
public EntireFormat(string mxml, string path)
{
MyPath = path;
XmlDocument xmldoc = new XmlDocument();
XmlComment copyright = xmldoc.CreateComment("Proprietary Information - Copyright 2012 - Volian Enterprises, Inc. All rights reserved.");
XmlElement top = xmldoc.CreateElement("PlantFormat");
xmldoc.AppendChild(copyright);
xmldoc.AppendChild(top);
try
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
StreamReader strrdr = new StreamReader(mxml);
XmlTextReader rdr = new XmlTextReader(strrdr);
using (rdr)
{
rdr.MoveToContent();
XmlNode fmt = xmldoc.ReadNode(rdr);
top.AppendChild(fmt);
}
rdr.Close();
// load page xml
string pagename = mxml.Substring(0, mxml.Length - 5) + "p.xml";
using (XmlReader reader = XmlReader.Create(pagename, settings))
{
reader.MoveToContent();
XmlNode pag = xmldoc.ReadNode(reader);
top.AppendChild(pag);
}
string docname = mxml.Substring(0, mxml.Length - 5) + "d.xml";
using (XmlReader reader = XmlReader.Create(docname, settings))
{
reader.MoveToContent();
XmlNode doc = xmldoc.ReadNode(reader);
top.AppendChild(doc);
}
string outname = MyPath + @"\fmtall\" + mxml.Substring(mxml.IndexOf("\\")+1,mxml.Length - 13) + "all.xml";
XmlWriterSettings settingsout = new XmlWriterSettings();
settingsout.Encoding = Encoding.Unicode;
settingsout.Indent = true;
settingsout.IndentChars = "\t";
XmlWriter xmlwrite = XmlWriter.Create(outname,settingsout);
xmldoc.WriteContentTo(xmlwrite);
xmlwrite.Close();
XmlDocument newDoc = new XmlDocument();
newDoc.Load(outname);
XmlNodeReader xtr = new XmlNodeReader(newDoc);
XmlTextWriter xtw = new XmlTextWriter(outname, Encoding.Unicode);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 1;
xtw.IndentChar = '\t';
xtw.WriteNode(xtr, true);
xtr.Close();
xtw.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error on merge, format = {0}, msg = {1}", mxml, ex.Message);
}
}
}
}