Example #1
0
        public XmlDocument Export(XmlDocument doc, XmlDocument interpreter)
        {
            //default type
            XmlNode defaultAttrib = null;

            defaultAttrib = interpreter.SelectSingleNode("/Converts/Default");
            var converts        = interpreter.SelectNodes("/Converts/Converts/Convert");
            var internalFileDBs = interpreter.SelectNodes("/Converts/InternalCompression/Element");

            //converts
            foreach (XmlNode x in converts)
            {
                try
                {
                    String Path  = x.Attributes["Path"].Value;
                    var    Nodes = doc.SelectNodes(Path);
                    ConvertNodeSet(Nodes, x);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Path not correctly set lol");
                    Console.WriteLine(x.Attributes["Path"].Value);
                }
            }

            //defaultType
            if (defaultAttrib != null)
            {
                //get a combined xpath of all
                List <String> StringList = new List <string>();
                foreach (XmlNode convert in converts)
                {
                    StringList.Add(convert.Attributes["Path"].Value);
                }
                foreach (XmlNode internalFileDB in internalFileDBs)
                {
                    StringList.Add(internalFileDB.Attributes["Path"].Value);
                }
                String xPath = String.Join(" | ", StringList);

                //select all text not in combined path#
                var Base     = doc.SelectNodes("//*[text()]");
                var toFilter = doc.SelectNodes(xPath);
                var defaults = HexHelper.ExceptNodelists(Base, toFilter);

                //convert that to default type
                ConvertNodeSet(defaults, defaultAttrib);
            }
            //internal filedbs
            foreach (XmlNode n in internalFileDBs)
            {
                var nodes = doc.SelectNodes(n.Attributes["Path"].Value);
                foreach (XmlNode node in nodes)
                {
                    //get internal document
                    var         contentNode = node.SelectSingleNode("./Content");
                    XmlDocument xmldoc      = new XmlDocument();
                    XmlNode     f           = xmldoc.ImportNode(contentNode, true);
                    xmldoc.AppendChild(xmldoc.ImportNode(f, true));

                    //compress the document
                    FileWriter fileWriter = new FileWriter();
                    var        stream     = fileWriter.Export(xmldoc, new MemoryStream());

                    //get this stream to hex
                    node.InnerText = ByteArrayToString(HexHelper.StreamToByteArray(stream));

                    //try to overwrite the bytesize since it's always exported the same way
                    var ByteSize = node.SelectSingleNode("./preceding-sibling::ByteCount");
                    if (ByteSize != null)
                    {
                        long BufferSize = stream.Length;
                        Type type       = typeof(int);
                        ByteSize.InnerText = ByteArrayToString(ConverterFunctions.ConversionRulesExport[type](BufferSize.ToString(), new UnicodeEncoding()));
                    }
                }
            }

            return(doc);
            //doc.Save(Path.ChangeExtension(HexHelper.AddSuffix(docpath, "_e"), "xml"));
        }