quarta-feira, 29 de julho de 2015

HashXML

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;
using System.Xml;



namespace Lapuinka.Util
{
    class HashXML
    {
        private String nameFileXML;
        private String[] totemTypes;

        public HashXML(String fileOpen, String[] totemTypes)
        {
            nameFileXML = fileOpen;
            this.totemTypes = totemTypes;
        }

        public Hashtable createHash()
        {
            Hashtable hashXMLServer = new Hashtable();
            XmlDocument xDoc = new XmlDocument();

            try
            {
                xDoc.Load(nameFileXML);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            XmlNodeList xnlResultKey = xDoc.SelectNodes("//file");

            foreach (XmlNode nodeADD in xnlResultKey)
            {
                Boolean found = false;
                foreach (string totemType in totemTypes)
                {
                    if (nodeADD[totemType] != null)
                    {
                        DataIMG di = new DataIMG();
                        di.Dig = totemType;
                        di.Version = nodeADD[totemType].Attributes["version"].Value;

                        hashXMLServer.Add(nodeADD.Attributes["name"].Value, di);

                        found = true;
                        break;
                    }
                }

                if(!found)
                {
                    DataIMG di = new DataIMG();
                    di.Dig = "family";
                    di.Version = nodeADD["family"].Attributes["version"].Value;

                    hashXMLServer.Add(nodeADD.Attributes["name"].Value, di);
                }

            }

            return hashXMLServer;
        }
    }
}


Postar um comentário