Beispiel #1
0
        parseXML(     MemoryStream    XmlCompressedStream    ) {
            ////////////////////////////////////////////////////
            MemoryStream XmlDecompressedStream = new MemoryStream();
            XmlDecompressedStream = Exflator.decompress(XmlCompressedStream);

            /*** Rimozione dall'heap degli oggetti oramai non più utili ***/
            XmlCompressedStream.Close();
            XmlCompressedStream.Dispose();

            XmlDecompressedStream.Position = 0;
            XmlReader reader = XmlReader.Create(XmlDecompressedStream);
            /*
            /*** Controllo se il file XML contiene un albero ***
            while (reader.Read()) {
                if (reader.NodeType == XmlNodeType.Element) {
                    switch(reader.Name) {

                        case "tree":
                            break;

                        case "header":
                            return null;
                    }
                }
            }
            */
                                      /*** Analisi del custom XML header ***/
            /*** Strutture ed oggetti che verranno riempiti per costruire l'albero ***/
            String treeName = "";
            String treeType = "";
            int treeSplit = 0;
            int treeDepth = 0;
            Dictionary<String, String[]> nodeAttributeList = new Dictionary<String, String[]>();
            Dictionary<String, String[]> edgeAttributeList = new Dictionary<String, String[]>();

            /*** Finchè non si raggiunge la treeDepth non si e' conclusa l'analisi dell'header ***/
            bool EndOfTreeInfo = false;

            while (reader.Read() && !EndOfTreeInfo) {
                if (reader.NodeType == XmlNodeType.Element) {
                    switch(reader.Name) {

                        case "treeName":
                            while (reader.Read()) {
                                if (reader.NodeType == XmlNodeType.Text) {
                                    treeName = reader.Value;
                                    break;
                                }
                            }
                            break;

                        case "treeType":
                            while (reader.Read()) {
                                if (reader.NodeType == XmlNodeType.Text) {
                                    treeType = reader.Value;
                                    break;
                                }
                            }
                            break;

                        case "treeSplit":
                            while (reader.Read()) {
                                if (reader.NodeType == XmlNodeType.Text) {
                                    treeSplit = Int32.Parse(reader.Value);
                                    break;
                                }
                            }
                            break;

                        case "treeDepth":
                            while (reader.Read()) {
                                if (reader.NodeType == XmlNodeType.Text) {
                                    treeDepth = Int32.Parse(reader.Value);
                                    EndOfTreeInfo = true;
                                    break;
                                }
                            }
                            break; 
                    }    
                } 
            }
            nodeAttributeList = FileEngine.nodeAttrParser(XmlDecompressedStream);
            edgeAttributeList = FileEngine.edgeAttrParser(XmlDecompressedStream);
            Albero Tree = new Albero(treeName, treeType, treeSplit, treeDepth, nodeAttributeList, edgeAttributeList);

                                        /*** Analisi dell'XML elementTable ***/
            restoreValues(Tree, XmlDecompressedStream);
            
            return Tree;
        } // End of method parseXML()
Beispiel #2
0
        assembleXML(    Albero      Tree    ) {
            ///////////////////////////////////

            /*** Settaggio impostazioni XmlWriter ***/
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.IndentChars = ("\t");
            settings.Encoding = System.Text.Encoding.UTF8;
            settings.NewLineChars = Environment.NewLine;
            settings.NewLineHandling = NewLineHandling.Replace;
            settings.OmitXmlDeclaration = false;

            MemoryStream XmlStream = new MemoryStream();
            XmlWriter writer = XmlWriter.Create(XmlStream, settings);

            /*** Inizio scrittura del codice XML ***/
            String depth = Convert.ToString(Tree.depth);
            String splitSize = Convert.ToString(Tree.splitSize);

            writer.WriteStartDocument();
            writer.WriteStartElement("tree");
                writer.WriteStartElement("header");
                    writer.WriteElementString("treeName", Tree.nome);
                    writer.WriteElementString("treeType", Tree.tipo);
                    writer.WriteElementString("treeSplit", splitSize);
                    writer.WriteElementString("treeDepth", depth);

                    writer.WriteStartElement("treeNodeAttributeList");
                        foreach (KeyValuePair<String, String[]> pair in Tree.VertexAttributeList) {
                            writer.WriteStartElement("treeNodeAttribute");
                                writer.WriteElementString("treeNodeAttrName", pair.Key.ToString());
                                writer.WriteElementString("treeNodeAttrType", pair.Value[0].ToString());
                                writer.WriteElementString("treeNodeAttrGenRule", pair.Value[1].ToString());
                            writer.WriteEndElement();
                        }
                    writer.WriteEndElement();

                    writer.WriteStartElement("treeEdgeAttributeList");
                        foreach (KeyValuePair<String, String[]> pair in Tree.EdgeAttributeList) {
                            writer.WriteStartElement("treeEdgeAttribute");
                                writer.WriteElementString("treeEdgeAttrName", pair.Key.ToString());
                                writer.WriteElementString("treeEdgeAttrType", pair.Value[0].ToString());
                                writer.WriteElementString("treeEdgeAttrGenRule", pair.Value[1].ToString());
                            writer.WriteEndElement();
                        }
                    writer.WriteEndElement();

                /*** Chiusura di header ***/
                writer.WriteEndElement();
            writer.WriteStartElement("elementTable");
            
            FileEngine.XmlTraversal(writer, Tree);

            /*** Chiusura di elementTable ***/
            writer.WriteEndElement();

            /*** Chiusura di tree ***/
            writer.WriteEndElement();
            writer.WriteEndDocument();

            writer.Flush();

            MemoryStream XmlCompressedStream = new MemoryStream();
            XmlCompressedStream = Exflator.compress(XmlStream);

            XmlStream.Close();
            XmlStream.Dispose();

            return XmlCompressedStream;
        } // End of method assembleXML()