Пример #1
0
        public bool parse()
        {
            System.IO.FileInfo fi = new System.IO.FileInfo(qrcFileName);
            if (!fi.Exists)
            {
                return(false);
            }
            try
            {
                XmlTextReader reader        = new XmlTextReader(qrcFileName);
                QrcItem       currentItem   = null;
                QrcPrefix     currentPrefix = null;
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (reader.LocalName.ToLower() == "qresource")
                        {
                            currentPrefix          = new QrcPrefix();
                            currentPrefix.Prefix   = reader.GetAttribute("prefix");
                            currentPrefix.Language = reader.GetAttribute("lang");
                            prefixes.Push(currentPrefix);
                        }
                        else if (reader.LocalName.ToLower() == "file")
                        {
                            currentItem       = new QrcItem();
                            currentItem.Alias = reader.GetAttribute("name");
                        }
                        break;

                    case XmlNodeType.EndElement:
                        if (reader.LocalName.ToLower() == "qresource")
                        {
                            prefxs.Add(prefixes.Pop());
                        }
                        else if (reader.LocalName.ToLower() == "file" &&
                                 prefixes.Peek() != null && currentItem != null)
                        {
                            ((QrcPrefix)(prefixes.Peek())).AddQrcItem(currentItem);
                            currentItem = null;
                        }
                        break;

                    case XmlNodeType.Text:
                        if (currentItem != null)
                        {
                            currentItem.Path = reader.Value;
                        }
                        break;
                    }
                }
                reader.Close();
            }
            catch (System.Exception)
            {
                return(false);
            }
            return(true);
        }
Пример #2
0
 public bool parse()
 {
     System.IO.FileInfo fi = new System.IO.FileInfo(qrcFileName);
     if (!fi.Exists)
         return false;
     try
     {
         XmlTextReader reader = new XmlTextReader(qrcFileName);
         QrcItem currentItem = null;
         QrcPrefix currentPrefix = null;
         while (reader.Read())
         {
             switch (reader.NodeType)
             {
                 case XmlNodeType.Element:
                     if (reader.LocalName.ToLower() == "qresource")
                     {
                         currentPrefix = new QrcPrefix();
                         currentPrefix.Prefix = reader.GetAttribute("prefix");
                         currentPrefix.Language = reader.GetAttribute("lang");
                         prefixes.Push(currentPrefix);
                     }
                     else if (reader.LocalName.ToLower() == "file")
                     {
                         currentItem = new QrcItem();
                         currentItem.Alias = reader.GetAttribute("name");
                     }
                     break;
                 case XmlNodeType.EndElement:
                     if (reader.LocalName.ToLower() == "qresource")
                     {
                         prefxs.Add(prefixes.Pop());
                     }
                     else if (reader.LocalName.ToLower() == "file"
                         && prefixes.Peek() != null && currentItem != null)
                     {
                         ((QrcPrefix)(prefixes.Peek())).AddQrcItem(currentItem);
                         currentItem = null;
                     }
                     break;
                 case XmlNodeType.Text:
                     if (currentItem != null)
                         currentItem.Path = reader.Value;
                     break;
             }
         }
         reader.Close();
     }
     catch (System.Exception)
     {
         return false;
     }
     return true;
 }