MoveToFirstAttribute() публичный Метод

public MoveToFirstAttribute ( ) : bool
Результат bool
        public OpenXML_Zefania_XML_Bible_Markup_Language(string fileLocation, bible_data.BookManipulator manipulator)
        {
            _fileLocation = fileLocation;
            _reader = new XmlTextReader(_fileLocation);
            _bible = manipulator;

            // Create an XmlReader for <format>Zefania XML Bible Markup Language</format>
            using (_reader)
            {
                _reader.ReadToFollowing("title");
                String title = _reader.ReadElementContentAsString();
                _bible.SetVersion(title);

                String book;
                int verseNumber;
                int chapterNumber;
                string verseString;

                while (_reader.ReadToFollowing("BIBLEBOOK")) // read each book name
                {
                    _reader.MoveToAttribute(1);
                    book = _reader.Value;
                    _reader.ReadToFollowing("CHAPTER");
                    while (_reader.Name == "CHAPTER") // read each chapter
                    {
                        _reader.MoveToFirstAttribute();
                        chapterNumber = Convert.ToInt32(_reader.Value);

                        _reader.ReadToFollowing("VERS");
                        while (_reader.Name == "VERS") // read each verse
                        {
                            _reader.MoveToFirstAttribute();
                            verseNumber = Convert.ToInt32(_reader.Value);
                            _reader.Read();
                            verseString = _reader.Value;

                            sendToDataTree(book, verseNumber, chapterNumber, verseString);

                            _reader.Read();
                            _reader.Read();
                            _reader.Read();
                        }//end verse while

                        _reader.Read();
                        _reader.Read();
                    } //end chapter while
                } // end book while
            } //end using statement
        }
Пример #2
0
        public void readXml()
        {
            using (XmlTextReader reader = new XmlTextReader("dump.xml"))
            {
                reader.ReadToFollowing("range");
                while (reader.EOF == false)
                {

                    reader.MoveToFirstAttribute();
                    rangeNameList.Add(reader.Value);
                    reader.MoveToNextAttribute();
                    string temp = (reader.Value);
                    rangeNameList.Add(temp);
                    rangeStartList.Add(Int32.Parse(reader.Value, System.Globalization.NumberStyles.HexNumber));
                    reader.MoveToNextAttribute();
                    temp = (reader.Value);
                    rangeNameList.Add(temp);
                    int temp1 = (Int32.Parse(reader.Value, System.Globalization.NumberStyles.HexNumber));
                    int temp2 = rangeStartList[rangeStartList.Count-1];
                    rangeLengthList.Add(temp1-temp2);

                    reader.ReadToFollowing("range");
                }

            }
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            XmlTextReader tr =
                new XmlTextReader(@"D:\MS.Net\CSharp\XMLParser\XMLParser\Emp.xml");
            while (tr.Read())
            {
                //Check if it is a start tag
                if (tr.NodeType == XmlNodeType.Element)
                {
                    listBox1.Items.Add(tr.Name);
                    if (tr.HasAttributes)
                    {
                        tr.MoveToFirstAttribute();
                        string str = tr.Name;
                        str += " = ";
                        str += tr.Value;
                        listBox1.Items.Add(str);
                    }
                    if (tr.MoveToNextAttribute())
                    {

                        string str = tr.Name;
                        str += " = ";
                        str += tr.Value;
                        listBox1.Items.Add(str);
                    }
                }
                if (tr.NodeType == XmlNodeType.Text)
                {
                    listBox1.Items.Add(tr.Value);
                }

            }
        }
        private int EnumerateAttributes(string elementStartTag, Action<int, int, string> onAttributeSpotted)
        {
            bool selfClosed = (elementStartTag.EndsWith("/>", StringComparison.Ordinal));
            string xmlDocString = elementStartTag;
            if (!selfClosed)
            {
                xmlDocString = elementStartTag.Substring(0, elementStartTag.Length-1) + "/>" ;
            }

            XmlTextReader xmlReader = new XmlTextReader(new StringReader(xmlDocString));

            xmlReader.Namespaces = false;
            xmlReader.Read();

            bool hasMoreAttributes = xmlReader.MoveToFirstAttribute();
            while (hasMoreAttributes)
            {
                onAttributeSpotted(xmlReader.LineNumber, xmlReader.LinePosition, xmlReader.Name);
                hasMoreAttributes = xmlReader.MoveToNextAttribute();
            }

            int lastCharacter = elementStartTag.Length;
            if (selfClosed)
            {
                lastCharacter--;
            }
            return lastCharacter;
        }
Пример #5
0
 public List<string> LoadVideoFile(string file)
 {
     List<string> videos = new List<string>();
     using (XmlReader reader = new XmlTextReader(file))
     {
         do
         {
             switch (reader.NodeType)
             {
                 case XmlNodeType.Element:
                     reader.MoveToFirstAttribute();
                     title.Add(reader.Value);
                     reader.MoveToNextAttribute();
                     author.Add(reader.Value);
                     reader.MoveToNextAttribute();
                     videos.Add(reader.Value);
                     WriteXNBVideoData(reader.Value);
                     break;
             }
         } while (reader.Read());
     }
     title.RemoveAt(0);
     author.RemoveAt(0);
     videos.RemoveAt(0);
     return videos;
 }
Пример #6
0
        public ConnectionTriggerFileXml(FloorSet aFloorSet, SettingsBase aSetting) : base(aFloorSet, aSetting)
        {
            //获取初始化数据
            mFloorSet    = aFloorSet;
            mXmlFileName = (string)aSetting["XmlFileName"];

            mXmlReader = new XmlTextReader(mXmlFileName);
            mXmlReader.MoveToFirstAttribute();
        }
Пример #7
0
 public GBXMLContainer(XmlTextReader reader)
 {
     while (reader.NodeType != XmlNodeType.Element)
     {
         reader.Read();
     }
     name = reader.Name;
     // check if the element has any attributes
     if (reader.HasAttributes) {
         // move to the first attribute
         reader.MoveToFirstAttribute ();
         for (int i = 0; i < reader.AttributeCount; i++) {
             // read the current attribute
             reader.MoveToAttribute (i);
             if (AttributesToChildren)
             {
                 GBXMLContainer newChild = new GBXMLContainer();
                 newChild.name = reader.Name;
                 newChild.textValue = reader.Value;
                 children.Add(newChild);
             }
             else
             {
                 attributes [reader.Name] = reader.Value;
             }
         }
     }
     reader.MoveToContent ();
     bool EndReached = reader.IsEmptyElement;
     while (!EndReached && reader.Read()) {
         switch (reader.NodeType) {
         case XmlNodeType.Element:
             GBXMLContainer newChild = new GBXMLContainer (reader);
             children.Add (newChild);
             break;
         case XmlNodeType.Text:
             textValue = reader.Value;
             break;
         case XmlNodeType.XmlDeclaration:
         case XmlNodeType.ProcessingInstruction:
             break;
         case XmlNodeType.Comment:
             break;
         case XmlNodeType.EndElement:
             EndReached = true;
             break;
         }
     }
 }
 private void readXmlContent()
 {
     XmlTextReader reader = new XmlTextReader(".\\configurationFiles\\FilePaths.xml");
     String osName = externalCode.OSVersionInfo.Name.Split(new char[]{' '})[0].ToLower();
     while (reader.ReadToFollowing("os"))
     {
         reader.MoveToFirstAttribute();
         if (reader.Value.Equals(osName))
         {
             reader.ReadToFollowing("fileName");
             this.fileName = reader.ReadElementContentAsString();
             reader.ReadToFollowing("environmentVariable");
             this.environmentVariable = reader.ReadElementContentAsString();
             reader.ReadToFollowing("path");
             this.path = reader.ReadElementContentAsString();
             break;
         }
     }
 }
 internal void ReadPreservationInfo(string elementStartTag)
 {
     XmlTextReader xmlTextReader = new XmlTextReader((TextReader)new StringReader(elementStartTag));
     WhitespaceTrackingTextReader trackingTextReader = new WhitespaceTrackingTextReader((TextReader)new StringReader(elementStartTag));
     xmlTextReader.Namespaces = false;
     xmlTextReader.Read();
     for (bool flag = xmlTextReader.MoveToFirstAttribute(); flag; flag = xmlTextReader.MoveToNextAttribute())
     {
         this.orderedAttributes.Add(xmlTextReader.Name);
         if (trackingTextReader.ReadToPosition(xmlTextReader.LineNumber, xmlTextReader.LinePosition))
             this.leadingSpaces.Add(xmlTextReader.Name, trackingTextReader.PrecedingWhitespace);
     }
     int length = elementStartTag.Length;
     if (elementStartTag.EndsWith("/>", StringComparison.Ordinal))
         --length;
     if (!trackingTextReader.ReadToPosition(length))
         return;
     this.leadingSpaces.Add(string.Empty, trackingTextReader.PrecedingWhitespace);
 }
Пример #10
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            //  XmlTextReader reader1 = new XmlTextReader(folderBrowserDialog2.SelectedPath + "\\" + textBox2.Text + ".xml");
            //XmlTextReader reader = new XmlTextReader(folderBrowserDialog1.SelectedPath+"\\"+textBox1.Text+".xml");
            //XmlTextReader reader = new XmlTextReader("\\\\voting-1\\test-1\\shendy1.xml");
            //XmlTextReader reader1 = new XmlTextReader("\\\\voting-1\\test-1\\shendy1.xml");
            XmlTextReader reader = new XmlTextReader("c:\\users\\ali\\desktop\\whats your name.xml");
            XmlTextReader reader1 = new XmlTextReader("c:\\users\\ali\\desktop\\whats your name.xml");

            if (player.flag == 1)
            {
                player.Init();
                question_no = 0;
            }
            for (int i = 0; i <= question_no; i++)
            {
                reader.ReadToFollowing("Question");
            }
            if (!reader.EOF)
            {

                reader.MoveToAttribute(1);
                questions[question_no].title = reader.Value;

                reader.MoveToAttribute(5);
                questions[question_no].choices_no = reader.Value;
                choices_no1 = Convert.ToInt32(questions[question_no].choices_no);
                //reader.ReadToFollowing("Data");
                for (int i = 0; i < choices_no1; ++i)
                {

                    reader.ReadToFollowing("Data");
                    reader.MoveToFirstAttribute();
                    questions[question_no].choices.Add(reader.Value);
                    reader.MoveToContent();

                    questions[question_no].values.Add(reader.ReadElementContentAsInt());

                }

            }
            for (int i = 0; i <= question_no; i++)
            {
                reader1.ReadToFollowing("Question");
            }
            if (!reader1.EOF)
            {

                // reader1.ReadToFollowing("Data");

                for (int i = 0; i < choices_no1; i++)
                {
                    reader1.ReadToFollowing("Data");

                    reader1.MoveToContent();

                    questions[question_no].values[i] = (questions[question_no].values[i] + reader1.ReadElementContentAsInt());

                }

                player.add_slide(ref question_no, ref questions, ref openFileDialog1);
                player.add_title(ref questions, ref question_no);
                player.add_choices(ref questions, ref question_no, ref choices_no1);
                player.add_chart(ref questions, ref question_no, ref choices_no1, ref colorDialog1, ref data_format, ref bar_colors, ref fontDialog1);
                player.start_show(ref question_no);
                question_no++;

            }

            reader.Close();
            reader1.Close();
            actHook = new UserActivityHook(false, true);
            actHook.KeyPress += new KeyPressEventHandler(key_pressed);
            button1.Text = "Show Started";
            button1.Enabled = false;
            player.objApp.ActivePresentation.SaveAs(saveFileDialog1.FileName);
        }
Пример #11
0
        private void loadData()
        {
            XmlTextReader reader = new XmlTextReader(contentPath + "\\Armors.item");
            reader.WhitespaceHandling = WhitespaceHandling.None;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "Armor")
                    {
                        armor.name = reader["Name"];
                        armor.type = reader["Type"];
                    }
                    if (reader.Name == "Equip")
                    {
                        reader.MoveToFirstAttribute();
                        string[] eachClass = reader.Value.Split(' ');
                        foreach(string s in eachClass)
                            if (!s.Contains(" "))
                                armor.equipClass.Add(s);
                    }
                    if (reader.Name == "Image")
                        armor.textureName = contentPath + "\\" + reader["Texture"];
                    if (reader.Name == "Def")
                        armor.def = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "Str")
                        armor.strbonus = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "Dex")
                        armor.dexbonus = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "Agi")
                        armor.agibonus = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "Sta")
                        armor.stabonus = int.Parse(reader.ReadInnerXml());
                    if (reader.Name == "DefenseType")
                        armor.defenseType = reader.ReadInnerXml();
                }

                else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Armor")
                {
                    armorList.Add(armor.name, armor);
                    existingArmorComboBox.Items.Add(armor.name);
                    armor = new Armor();
                }
            }
            reader.Close();
        }
Пример #12
0
        /// <summary>
        /// Load a query from a file
        /// </summary>
        public static Query Deserialize(string outfile)
        {
            List<OperatorParams> ops = new List<OperatorParams>();
            int idTopOperator = -1;
            using (XmlTextReader reader = new XmlTextReader(outfile))
            {
                reader.Read();
                idTopOperator = Int32.Parse(reader.GetAttribute(XMLTOPID));
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        ops.Add(new OperatorParams());
                        ops[ops.Count - 1].opName = reader.Name;
                        ops[ops.Count - 1].opParams = new string[reader.AttributeCount];
                        reader.MoveToFirstAttribute();
                        int i = 0;
                        do
                        {
                            if (reader.Name == XMLINPUTID)
                            {
                                ops[ops.Count - 1].rginputs = new int[1];
                                ops[ops.Count - 1].rginputs[0] = Int32.Parse(reader.Value);
                            }
                            else if (reader.Name == XMLLEFTINPUTID)
                            {
                                if (ops[ops.Count - 1].rginputs == null)
                                    ops[ops.Count - 1].rginputs = new int[2];
                                ops[ops.Count - 1].rginputs[0] = Int32.Parse(reader.Value);
                            }
                            else if (reader.Name == XMLRIGHTINPUTID)
                            {
                                if (ops[ops.Count - 1].rginputs == null)
                                    ops[ops.Count - 1].rginputs = new int[2];
                                ops[ops.Count - 1].rginputs[1] = Int32.Parse(reader.Value);
                            }
                            else if (reader.Name == XMLINPUTCOUNT)
                                ops[ops.Count - 1].rginputs = new int[Int32.Parse(reader.Value)];
                            else if (ops[ops.Count-1].rginputs != null)
                            {
                                //Check to see if this is an expected input number
                                for (int j = 0; j < ops[ops.Count - 1].rginputs.Length; j++)
                                {
                                    if (reader.Name == string.Format("{0}{1}", XMLINPUTID, j))
                                        ops[ops.Count - 1].rginputs[j] = Int32.Parse(reader.Value);
                                }
                            }

                            ops[ops.Count - 1].opParams[i] =
                                string.Format("{0}={1}", reader.Name, reader.Value);
                            i++;
                        } while (reader.MoveToNextAttribute());
                    }
                }

                reader.Close();
            }

            //Now, build the query plan
            return BuildQueryPlan(ops, idTopOperator);
        }
Пример #13
0
        private void button3_Click(object sender, EventArgs e)
        {
            XmlTextReader tr = new XmlTextReader(@"D:\nt-pritz\MS.NET\MS FRAMEWORK\CLASS DEMO\WindowsFormsApplication2\WindowsFormsApplication2\XMLFile1.xml");
            while (tr.Read())
            {
                if(tr.NodeType==XmlNodeType.Element)
                    listBox2.Items.Add(tr.Name);

                if (tr.NodeType == XmlNodeType.Text)
                    listBox2.Items.Add(tr.Value);

                if (tr.NodeType == XmlNodeType.Element)
                {
                    //listBox2.Items.Add(tr.Name);
                    if (tr.HasAttributes)
                    {
                        tr.MoveToFirstAttribute();
                        string str = tr.Name;
                        str += " : ";
                        str += tr.Value;
                        listBox2.Items.Add(str);
                    }
                    if (tr.MoveToNextAttribute())
                    {
                        string str = tr.Name;
                        str += " : ";
                        str += tr.Value;
                        listBox2.Items.Add(str);
                    }
                    if (tr.NodeType == XmlNodeType.Text)
                    {
                        listBox2.Items.Add(tr.Value);
                    }
                }
            }
        }
Пример #14
0
        public int ParseConfig(string configFile, bool bDeep = false)
        {
            //
            // Consume XML to create the XFSEntity objects.
            // if bDeep is false, then ONLY do this object.
            // if bDeep is true, then also do recursive objects.
            XmlTextReader reader = null;

            int rc = -1;
            string connectString = XTRMObject.getDictionaryEntry("TaskConnectString");
            string outerXML;
            int lElementType = 0;
            XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
            Dictionary<String, String> elementAttributes;
            entities.Clear();
            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                reader = new XmlTextReader(configFile);
                reader.WhitespaceHandling = WhitespaceHandling.None;
                // Parse the file and display each of the nodes.
                bool bResult = reader.Read();
                while (bResult)
                {
                    bool bProcessed = false;
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            string elementName = reader.Name;
                            switch (elementName.ToUpper())
                            {
                                case "XFSENTITY":
                                    outerXML = reader.ReadOuterXml();
                                    XTRMFSEntity thisEntity = (XTRMFSEntity)XTRMFSEntity.consumeXML(outerXML, 1, true);
                                    entities.Add(thisEntity);
                                    bProcessed = true;
                                    break;
                            }
                            if (!bProcessed)
                            {
                                // May wish to get all the  attributes here for new elements!
                                elementAttributes = new Dictionary<String, String>();
                                if (reader.HasAttributes)
                                {
                                    reader.MoveToFirstAttribute();
                                    for (int i = 0; i < reader.AttributeCount; i++)
                                    {
                                        //reader.GetAttribute(i);
                                        elementAttributes.Add(reader.Name, reader.Value);
                                        reader.MoveToNextAttribute();
                                    }
                                    if (elementAttributes.ContainsKey("Tag"))
                                    {
                                        agentTag = elementAttributes["Tag"];
                                    }
                                    if (elementAttributes.ContainsKey("Source"))
                                    {
                                        agentSource = elementAttributes["Source"];
                                    }
                                    if (elementAttributes.ContainsKey("User"))
                                    {
                                        agentUser = elementAttributes["User"];
                                    }
                                    if (elementAttributes.ContainsKey("EventPath"))
                                    {
                                        agentEventPath = elementAttributes["EventPath"];
                                    }
                                    reader.MoveToElement();
                                }
                                // Need to see if we are interested in this element!
                                //string elementName = reader.Name;
                                switch (elementName.ToUpper())
                                {
                                    case "XFILEAGENTCONFIG":
                                        // Advance into Elements!
                                        reader.MoveToContent();
                                        bResult = reader.Read();
                                        break;
                                    default:
                                        bResult = reader.Read();
                                        break;
                                }
                            }
                            break;
                        case XmlNodeType.XmlDeclaration:
                        case XmlNodeType.ProcessingInstruction:
                            //writer.WriteProcessingInstruction(reader.Name, reader.Value);
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.Comment:
                            //writer.WriteComment(reader.Value);
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.EndElement:
                            //writer.WriteFullEndElement();
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.Text:
                            //Console.Write(reader.Value);
                            switch (lElementType)
                            {
                                default:
                                    break;
                            }
                            bResult = reader.Read();
                            break;
                        default:
                            bResult = reader.Read();
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                exCount_XML++;
                XLogger(2400, -1, string.Format("XTRMFileAgent::parseConfig(); ConfigFile={0}; Message={1}", configFile, ex.Message));
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }

            return rc;
        }
Пример #15
0
 private static void TestXmlReader()
 {
     using (var fileStream = File.OpenRead(Path.Combine("save", "test.xml")))
     {
         using (var xmlTextReader = new XmlTextReader(fileStream))
         {
             while (xmlTextReader.Read())
             {
                 if (xmlTextReader.NodeType != XmlNodeType.Element) continue;
                 if (xmlTextReader.LocalName != "contents") continue;
                 xmlTextReader.MoveToFirstAttribute();
                 if (xmlTextReader.Value != "question") continue;
                 xmlTextReader.Read();
                 Console.WriteLine(xmlTextReader.Value);
             }
         }
     }
 }
		public void ExpandEntity ()
		{
			string intSubset = "<!ELEMENT root (#PCDATA)><!ATTLIST root foo CDATA 'foo-def' bar CDATA 'bar-def'><!ENTITY ent 'entity string'>";
			string dtd = "<!DOCTYPE root [" + intSubset + "]>";
			string xml = dtd + "<root foo='&ent;' bar='internal &ent; value'>&ent;</root>";
			XmlTextReader dvr = new XmlTextReader (xml, XmlNodeType.Document, null);
			dvr.EntityHandling = EntityHandling.ExpandEntities;
			dvr.Read ();	// DTD
			dvr.Read ();
			AssertEquals (XmlNodeType.Element, dvr.NodeType);
			AssertEquals ("root", dvr.Name);
			Assert (dvr.MoveToFirstAttribute ());
			AssertEquals ("foo", dvr.Name);
			AssertEquals ("entity string", dvr.Value);
			Assert (dvr.MoveToNextAttribute ());
			AssertEquals ("bar", dvr.Name);
			AssertEquals ("internal entity string value", dvr.Value);
			AssertEquals ("entity string", dvr.ReadString ());
		}
		public void QuoteChar ()
		{
			string xml = @"<a value='hello &amp; world' value2="""" />";
			XmlReader xmlReader =
				new XmlTextReader (new StringReader (xml));
			xmlReader.Read ();
			xmlReader.MoveToFirstAttribute ();
			AssertEquals ("First", '\'', xmlReader.QuoteChar);
			xmlReader.MoveToNextAttribute ();
			AssertEquals ("Next", '"', xmlReader.QuoteChar);
			xmlReader.MoveToFirstAttribute ();
			AssertEquals ("First.Again", '\'', xmlReader.QuoteChar);
		}
Пример #18
0
        internal static string GetCurrentTheme()
        {
            string theme = (string) HttpContext.Current.Items[ThemeCookieName];

            if (theme == null)
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[ThemeCookieName];
                if (cookie != null)
                {
                    theme = cookie.Value;

                    if (!String.IsNullOrEmpty(theme))
                    {
                        HttpContext.Current.Items[ThemeCookieName] = theme;
                        return theme;
                    }
                }
                else
                {
                    string appData = HttpContext.Current.Server.MapPath(CONFIG_FOLDER);
                    string path = Path.Combine(appData, SUPPORTED_THEMES_FILE);

                    XmlTextReader reader = new XmlTextReader(path);
                    reader.XmlResolver = null;
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    reader.MoveToContent();
                    if (reader.Name != null)
                    {
                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                if (reader.HasAttributes)
                                {
                                    reader.MoveToFirstAttribute();
                                    theme = reader.Value;
                                    return theme;
                                }
                            }
                        }
                    }
                }
            }
            return String.IsNullOrEmpty(theme) ? "Default" : theme;
        }
Пример #19
0
        /// <summary>
        /// Liefert den HTML-Text in Fließtextdarstellung.
        /// </summary>
        public string GetChapterAsFlowText(string BookNumber,string ChapterNumber)
        {
            try
            {
                StringWriter sw = new StringWriter();
                XmlTextWriter writer = new XmlTextWriter(sw);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartElement("html");

                writer.WriteStartElement("body");

                string pathToChapterFile=CachePathForModul+@"\"+BookNumber+"_"+ChapterNumber+@".xml";

                XmlTextReader reader = new XmlTextReader(pathToChapterFile);
                reader.MoveToContent();
                while (reader.Read())
                {
                    if(reader.Name=="VERS"&&reader.NodeType == XmlNodeType.Element)
                    {
                        writer.WriteStartElement("span");

                        reader.MoveToFirstAttribute();
                        writer.WriteStartElement("span");
                        writer.WriteAttributeString("style","color:darkred;font-weight:bold");

                        writer.WriteString(reader.Value+" ");
                        writer.WriteEndElement();
                    }

                    if(reader.Name==""&&reader.NodeType == XmlNodeType.Text)
                    {
                        writer.WriteStartElement("span");
                        writer.WriteString(reader.ReadString());
                        writer.WriteEndElement();

                    }

                    if (reader.Name == "NOTE")
                    {
                        writer.WriteStartElement("span");

                        writer.WriteAttributeString("style","color:darkgreen;font-weight:lighter");
                        writer.WriteString("{"+reader.ReadString()+"}");

                        writer.WriteEndElement();
                    }

                    if(reader.Name=="VERS"&&reader.NodeType == XmlNodeType.EndElement)
                    {

                        writer.WriteEndElement();

                    }
                }

                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.Close();
                reader.Close();
                return sw.ToString();
            }
            catch(Exception e)
            {

                return "<html><body><div>"+e.Message+"</div></body></html>";
            }
        }
Пример #20
0
 // TODO : ADDED FOR PS5
 /// <summary>
 /// Returns the version information of the spreadsheet saved in the named file.
 /// If there are any problems opening, reading, or closing the file, the method
 /// should throw a SpreadsheetReadWriteException with an explanatory message.
 /// </summary>
 public override string GetSavedVersion(string filename)
 {
     string vers = "";
     XmlTextReader xmlReader = null;
     try
     {
         xmlReader = new XmlTextReader(filename);
     }
     catch (Exception)
     {
         xmlReader.Dispose();
         throw new SpreadsheetReadWriteException("File could not be opened using XmlTextReader");
     }
     // Attempts to read the spreadsheet version from the XML file.
     if (!xmlReader.ReadToFollowing("spreadsheet") || !xmlReader.MoveToFirstAttribute())
         throw new SpreadsheetReadWriteException("Spreadsheet version could not be found");
     vers = xmlReader.Value;
     // Attemtps to close the XML reader.
     try
     {
         xmlReader.Close();
     }
     catch (Exception)
     {
         xmlReader.Dispose();
         throw new SpreadsheetReadWriteException("File could not be closed.");
     }
     return vers;
 }
Пример #21
0
        public void addd_ata()
        {
            //  XmlTextReader reader1 = new XmlTextReader(folderBrowserDialog2.SelectedPath + "\\" + textBox2.Text + ".xml");
            //XmlTextReader reader = new XmlTextReader(folderBrowserDialog1.SelectedPath+"\\"+textBox1.Text+".xml");
            //XmlTextReader reader = new XmlTextReader("\\\\voting-1\\test-1\\shendy1.xml");
            //XmlTextReader reader1 = new XmlTextReader("\\\\voting-1\\test-1\\shendy1.xml");
            XmlTextReader reader = new XmlTextReader("c:\\users\\ali\\desktop\\whats your name.xml");
            XmlTextReader reader1 = new XmlTextReader("c:\\users\\ali\\desktop\\whats your name.xml");

            for (int i = 0; i <= question_no; i++)
            {
                reader.ReadToFollowing("Question");
            }
            if (!reader.EOF)
            {

                reader.MoveToAttribute(1);
                questions[question_no].title = reader.Value;

                reader.MoveToAttribute(5);
                questions[question_no].choices_no = reader.Value;
                choices_no1 = Convert.ToInt32(questions[question_no].choices_no);
                //reader.ReadToFollowing("Data");
                for (int i = 0; i < choices_no1; ++i)
                {

                    reader.ReadToFollowing("Data");
                    reader.MoveToFirstAttribute();
                    questions[question_no].choices.Add(reader.Value);
                    reader.MoveToContent();

                    questions[question_no].values.Add(reader.ReadElementContentAsInt());

                }

            }
            for (int i = 0; i <= question_no; i++)
            {
                reader1.ReadToFollowing("Question");
            }
            if (!reader1.EOF)
            {

                // reader1.ReadToFollowing("Data");

                for (int i = 0; i < choices_no1; i++)
                {
                    reader1.ReadToFollowing("Data");

                    reader1.MoveToContent();

                    questions[question_no].values[i] = (questions[question_no].values[i] + reader1.ReadElementContentAsInt());

                }

                player.add_slide(ref question_no, ref questions, ref openFileDialog1);
                player.add_title(ref questions, ref question_no);
                player.add_choices(ref questions, ref question_no, ref choices_no1);
                player.add_chart(ref questions, ref question_no, ref choices_no1, ref colorDialog1, ref data_format, ref bar_colors, ref fontDialog1);
                player.start_show(ref question_no);
                question_no++;

            }

            reader.Close();
            reader1.Close();
            player.objApp.ActivePresentation.Save();
        }
		public void AttributeWithEntityReference ()
		{
			string xml = @"<a value='hello &ent; world' />";
			XmlReader xmlReader =
				new XmlTextReader (new StringReader (xml));
			xmlReader.Read ();
			xmlReader.MoveToFirstAttribute ();
			xmlReader.ReadAttributeValue ();
			AssertEquals ("hello ", xmlReader.Value);
			Assert (xmlReader.ReadAttributeValue ());
			AssertEquals (XmlNodeType.EntityReference, xmlReader.NodeType);
			AssertEquals ("ent", xmlReader.Name);
			AssertEquals (XmlNodeType.EntityReference, xmlReader.NodeType);
			Assert (xmlReader.ReadAttributeValue ());
			AssertEquals (" world", xmlReader.Value);
			AssertEquals (XmlNodeType.Text, xmlReader.NodeType);
			Assert (!xmlReader.ReadAttributeValue ());
			AssertEquals (" world", xmlReader.Value); // remains
			AssertEquals (XmlNodeType.Text, xmlReader.NodeType);
			xmlReader.ReadAttributeValue ();
			AssertEquals (XmlNodeType.Text, xmlReader.NodeType);
		}
Пример #23
0
		/// <summary>
		/// Parses the Log config file and extracts all archived logs.
		/// </summary>
		/// <returns>A Queue made of strings containing logs urls.</returns>
		public static Queue GetArchivedLogsUrls()
		{
			FileInfo info = new FileInfo(GameServer.Instance.Configuration.LogConfigFile);
			Queue dirList = new Queue();

			try
			{
				if (info.Exists)
				{
					Queue archiveList = new Queue(); // List made of all archived logs urls.

					// We parse the xml file to find urls of logs.
					XmlTextReader configFileReader = new XmlTextReader(info.OpenRead());
					configFileReader.WhitespaceHandling = WhitespaceHandling.None;
					while (configFileReader.Read())
					{
						if (configFileReader.LocalName == "file")
						{
							// First attribute of node file is the url of a Log.
							configFileReader.MoveToFirstAttribute();
							info = new FileInfo(configFileReader.ReadContentAsString());

							// Foreach file in the Log directory, we will return all logs with
							// the same name + an extension added when archived.
							foreach (string file in Directory.GetFiles(info.DirectoryName, info.Name + "*"))
							{
								// Only if this file is accessible we add it to the list we will return.
								if (file != info.FullName)
									archiveList.Enqueue(file);
							}
						}
					}
					return archiveList;
				}
				else
				{
					// We return the default value.
					Queue archiveList = new Queue(); // List made of all archived logs urls.
					archiveList.Enqueue("./logs/Cheats.Log");
					archiveList.Enqueue("./logs/GMActions.Log");
					archiveList.Enqueue("./logs/Error.Log");
					archiveList.Enqueue("./logs/GameServer.Log");
					return archiveList;
				}
			}
			catch (Exception e)
			{
				Logger.Error(e);
				return dirList;
			}
		}
		public void NormalizationAttributes ()
		{
			// does not normalize attribute values.
			StringReader sr = new StringReader ("<!DOCTYPE root [<!ELEMENT root EMPTY><!ATTLIST root attr ID #IMPLIED>]><root attr='   value   '/>");
			XmlTextReader xtr = new XmlTextReader (sr);
			xtr.Normalization = true;
			xtr.Read ();
			xtr.Read ();
			xtr.MoveToFirstAttribute ();
			AssertEquals ("   value   ", xtr.Value);
		}
Пример #25
0
        private static string FBRequest(Config config, string requestMethod, Hashtable htAddElements, out XmlTextReader xmlReader,
            string oAuthConsumerKey, string oAuthSecret, string parentElement)
        {
            string result = "Unexpected error.";
            xmlReader = null;
            HttpWebRequest fbRequest = (HttpWebRequest)WebRequest.Create(config.FBURL + "/api/2.1/xml-in");
            fbRequest.Headers.Add("Authorization", "OAuth realm=\"\",oauth_consumer_key=\""
                + Uri.EscapeDataString(oAuthConsumerKey) + "\",oauth_token=\"" + Uri.EscapeDataString(config.FBAccessToken)
                + "\",oauth_signature_method=\"PLAINTEXT\",oauth_signature=\"" + Uri.EscapeDataString(oAuthSecret + "&" + config.FBAccessTokenSecret)
                + "\",oauth_timestamp=\"" + Timestamp + "\",oauth_nonce=\"" + Nonce + "\", oauth_version=\"1.0\"");
            StringWriter sw = new StringWriter();
            XmlWriter xw = XmlWriter.Create(sw);
            xw.WriteStartDocument();
            xw.WriteStartElement("request");
            xw.WriteAttributeString("method", requestMethod);
            if (parentElement != "")
            {
                xw.WriteStartElement(parentElement);
            }
            if (htAddElements != null)
            {
                foreach (string key in htAddElements.Keys)
                {
                    xw.WriteElementString(key, htAddElements[key].ToString());
                }
            }
            if (parentElement != "")
            {
                xw.WriteEndElement();
            }
            xw.WriteEndElement();
            xw.Close();
            string command = sw.ToString();
            sw.Close();
            fbRequest.Method = "POST";
            fbRequest.ContentType = "application/xml";
            fbRequest.ContentLength = command.Length;
            StreamWriter requestWriter = new StreamWriter(fbRequest.GetRequestStream());
            try
            {
                requestWriter.Write(command);
            }
            catch
            {
                throw;
            }
            finally
            {
                requestWriter.Close();
                requestWriter = null;
            }

            try
            {
                using (HttpWebResponse fbResponse = (HttpWebResponse)fbRequest.GetResponse())
                {
                    Stream receiveStream = fbResponse.GetResponseStream();
                    StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
                    xmlReader = new XmlTextReader(new StringReader(readStream.ReadToEnd()));
                    xmlReader.Read();
                    xmlReader.Read();
                    xmlReader.Read();
                    xmlReader.MoveToFirstAttribute();
                    xmlReader.MoveToNextAttribute();
                    string xValue = xmlReader.Value;
                    if (xmlReader.Name == "status")
                    {
                        switch (xValue)
                        {
                            case "ok":
                                return "ok";
                            case "fail":
                                xmlReader.Read();
                                xmlReader.Read();
                                xmlReader.Read();
                                if (xmlReader.Value.IndexOf("Client limit of") >= 0)
                                {
                                    result = "Your Freshbook’s account has reached its limit for Customers. Please upgrade your FB account before proceeding";
                                }
                                else
                                {
                                    result = xmlReader.Value;
                                }
                                break;
                            default:
                                result = "Unrecognized API response status.";
                                break;
                        }
                    }
                    else
                    {
                        result = "Unrecognized API response.";
                    }
                    receiveStream.Close();
                    fbResponse.Close();
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return result;
        }
		public void PreserveEntity ()
		{
			string intSubset = "<!ELEMENT root EMPTY><!ATTLIST root foo CDATA 'foo-def' bar CDATA 'bar-def'><!ENTITY ent 'entity string'>";
			string dtd = "<!DOCTYPE root [" + intSubset + "]>";
			string xml = dtd + "<root foo='&ent;' bar='internal &ent; value' />";
			XmlTextReader dvr = new XmlTextReader (xml, XmlNodeType.Document, null);
			dvr.EntityHandling = EntityHandling.ExpandCharEntities;
			dvr.Read ();	// DTD
			dvr.Read ();
			AssertEquals (XmlNodeType.Element, dvr.NodeType);
			AssertEquals ("root", dvr.Name);
			Assert (dvr.MoveToFirstAttribute ());
			AssertEquals ("foo", dvr.Name);
			// MS BUG: it returns "entity string", however, entity should not be exanded.
			AssertEquals ("&ent;", dvr.Value);
			//  ReadAttributeValue()
			Assert (dvr.ReadAttributeValue ());
			AssertEquals (XmlNodeType.EntityReference, dvr.NodeType);
			AssertEquals ("ent", dvr.Name);
			AssertEquals ("", dvr.Value);
			Assert (!dvr.ReadAttributeValue ());

			// bar
			Assert (dvr.MoveToNextAttribute ());
			AssertEquals ("bar", dvr.Name);
			AssertEquals ("internal &ent; value", dvr.Value);
			//  ReadAttributeValue()
			Assert (dvr.ReadAttributeValue ());
			AssertEquals (XmlNodeType.Text, dvr.NodeType);
			AssertEquals ("", dvr.Name);
			AssertEquals ("internal ", dvr.Value);
			Assert (dvr.ReadAttributeValue ());
			AssertEquals (XmlNodeType.EntityReference, dvr.NodeType);
			AssertEquals ("ent", dvr.Name);
			AssertEquals ("", dvr.Value);
			Assert (dvr.ReadAttributeValue ());
			AssertEquals (XmlNodeType.Text, dvr.NodeType);
			AssertEquals ("", dvr.Name);
			AssertEquals (" value", dvr.Value);

		}
Пример #27
0
        public static XTRMObject consumeXML(string XmlFragment, int lVariant = 0, bool bDeep = false)
        {
            //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
            //myDictionaryLoader.Augment();
            //
            // Consume XML to create the XComponent object.
            // if bDeep is false, then ONLY do this object.
            // if bDeep is true, then also do recursive objects.
            XmlTextReader reader = null;
            XmlParserContext context = null;
            XTRMConfig thisEntity = null;
            if (lVariant == 1)
            {
                thisEntity = new XTRMConfig();
                thisEntity.Initialize(-1);
            }
            else
            {
                thisEntity = new XTRMConfig();
            }
            thisEntity.variant = lVariant;

            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                context = new XmlParserContext(null, null, null, XmlSpace.None);
                reader = new XmlTextReader(XmlFragment, XmlNodeType.Element, context);
                reader.WhitespaceHandling = WhitespaceHandling.None;
                // Parse the file and display each of the nodes.
                bool bResult = reader.Read();
                int lElementType = 0;
                XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
                Dictionary<String, String> elementAttributes;
                while (bResult)
                {
                    bool bProcessed = false;
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            string elementName = reader.Name;
                            if (!bProcessed)
                            {
                                // May wish to get all the attributes here for new elements!
                                elementAttributes = new Dictionary<String, String>();
                                if (reader.HasAttributes)
                                {
                                    reader.MoveToFirstAttribute();
                                    for (int i = 0; i < reader.AttributeCount; i++)
                                    {
                                        //reader.GetAttribute(i);
                                        elementAttributes.Add(reader.Name.ToUpper(), reader.Value);
                                        reader.MoveToNextAttribute();
                                    }
                                    // Check to see if ID is supplied!
                                    //if (elementAttributes["ID"] != null)
                                    if (elementAttributes.ContainsKey("TAG"))
                                    {
                                        thisEntity.entityTag = elementAttributes["TAG"];
                                    }
                                    if (elementAttributes.ContainsKey("SOURCE"))
                                    {
                                        thisEntity.entitySource = elementAttributes["SOURCE"];
                                    }
                                    if (elementAttributes.ContainsKey("USER"))
                                    {
                                        thisEntity.entityUser = elementAttributes["USER"];
                                    }
                                    if (elementAttributes.ContainsKey("PATH"))
                                    {
                                        thisEntity.entityPath = elementAttributes["PATH"];
                                    }
                                    if (elementAttributes.ContainsKey("PATTERN"))
                                    {
                                        thisEntity.entityPattern = elementAttributes["PATTERN"];
                                    }
                                    if (elementAttributes.ContainsKey("RECURSE"))
                                    {
                                        thisEntity.entityRecurse = Convert.ToInt16(elementAttributes["RECURSE"]);
                                    }
                                    if (elementAttributes.ContainsKey("BUFSIZE"))
                                    {
                                        thisEntity.entityBufsize = Convert.ToInt16(elementAttributes["BUFSIZE"]);
                                    }
                                    if (elementAttributes.ContainsKey("HOLDTIME"))
                                    {
                                        thisEntity.entityHoldTime = Convert.ToInt16(elementAttributes["HOLDTIME"]);
                                    }
                                    if (elementAttributes.ContainsKey("SCHEMA"))
                                    {
                                        thisEntity.entitySchema = elementAttributes["SCHEMA"];
                                    }
                                    reader.MoveToElement();
                                }
                                // Need to see if we are interested in this element!
                                //string elementName = reader.Name;
                                switch (elementName.ToUpper())
                                {
                                    case "PATH": // Path
                                        lElementType = 1;
                                        bResult = reader.Read();
                                        break;
                                    case "PATTERN": // Pattern
                                        lElementType = 2;
                                        bResult = reader.Read();
                                        break;
                                    case "RECURSE": // Recurse
                                        lElementType = 3;
                                        bResult = reader.Read();
                                        break;
                                    case "BUFSIZE": // Bufsize
                                        lElementType = 4;
                                        bResult = reader.Read();
                                        break;
                                    case "HOLDTIME": // HoldTime
                                        lElementType = 5;
                                        bResult = reader.Read();
                                        break;
                                    default:
                                        bResult = reader.Read();
                                        break;
                                }
                            }
                            break;
                        case XmlNodeType.XmlDeclaration:
                        case XmlNodeType.ProcessingInstruction:
                            //writer.WriteProcessingInstruction(reader.Name, reader.Value);
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.Comment:
                            //writer.WriteComment(reader.Value);
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.EndElement:
                            //writer.WriteFullEndElement();
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.Text:
                            //Console.Write(reader.Value);
                            switch (lElementType)
                            {
                                case 1:     // Path
                                    thisEntity.entityPath = reader.Value;
                                    break;
                                case 2:     // Pattern
                                    thisEntity.entityPattern = reader.Value;
                                    break;
                                case 3:     // Recurse
                                    thisEntity.entityRecurse = Convert.ToInt16(reader.Value);
                                    break;
                                case 4:     // Bufsize
                                    thisEntity.entityBufsize = Convert.ToInt16(reader.Value);
                                    break;
                                case 5:     // HoldTime
                                    thisEntity.entityHoldTime = Convert.ToInt16(reader.Value);
                                    break;
                                default:
                                    break;
                            }
                            lElementType = 0;
                            bResult = reader.Read();
                            break;
                        default:
                            bResult = reader.Read();
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                exCount_XML++;
                XLogger(2210, -1, string.Format("XML={0}; Message={1}", XmlFragment, ex.Message));
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
            return thisEntity;
        }
Пример #28
0
        private void LoadPreferences()
        {
            string daclr = "";
            string taclr = "";
            string selclr = "";

            try
            {
                XmlTextReader xmlReader = new XmlTextReader(this.preferencesFile);
                xmlReader.MoveToContent();
                xmlReader.MoveToFirstAttribute();

                xmlReader.Read();
                xmlReader.Read();

                daclr = xmlReader.GetAttribute("drawing-area");
                taclr = xmlReader.GetAttribute("tool-area");
                selclr = xmlReader.GetAttribute("selection");

                xmlReader.Close();

            }catch(IOException ioex)
            {
                MessageBox.ShowError("There was an error loading the preferences file.\n" + ioex.Message);
            }catch(Exception ex)
            {
                MessageBox.ShowError("There was an error reading the preferences file.\n" + ex.Message);
            }

            // drawing area
            Gdk.Color c = new Gdk.Color(0, 0, 0);
            Gdk.Color.Parse(daclr, ref c);
            this.drawingarea.ModifyBg(StateType.Normal, c);

            // tool area
            Gdk.Color.Parse(taclr, ref c);
            this.ModifyBg(StateType.Normal, c);
            this.iconview.ModifyBase(StateType.Normal, c);

            // selection rectangle (no effect)
            Gdk.Color.Parse(selclr, ref c);
            Shape.SelectionColor = new Cairo.Color((double)c.Red/65025,
                                                   (double)c.Green/65025,
                                                   (double)c.Blue/65025,
                                                   0.5);
        }
Пример #29
0
 //public Dictionary<String, String> createDictionary()
 //{
 // Populate the Dictionary!
 //    XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
 //    return myDictionaryLoader.ParseXML();
 //}
 /*
 public new static XObject consumeXML(Dictionary<String, String> myConfig, string XmlElement, bool bDeep = false)
 {
     //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
     //myDictionaryLoader.Augment();
     //
     // Consume XML to create the XComponent object.
     // if bDeep is false, then ONLY do this object.
     // if bDeep is true, then also do recursive objects.
     return new XComponent();
 }
  * */
 public static new XTRMObject consumeXML(Dictionary<String, String> existingConfig, string XmlFragment, int lVariant = 0, bool bDeep = false)
 {
     //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
     //myDictionaryLoader.Augment();
     //
     // Consume XML to create the XComponent object.
     // if bDeep is false, then ONLY do this object.
     // if bDeep is true, then also do recursive objects.
     XmlTextReader reader = null;
     XmlParserContext context = null;
     Dictionary<String, String> myConfig = new Dictionary<string, string>(existingConfig);
     XTRMWorkFlow thisWorkflow = new XTRMWorkFlow();
     int lElementType = 0;
     XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
     Dictionary<String, String> elementAttributes;
     try
     {
         // Load the reader with the data file and ignore all white space nodes.
         context = new XmlParserContext(null, null, null, XmlSpace.None);
         reader = new XmlTextReader(XmlFragment, XmlNodeType.Element, context);
         reader.WhitespaceHandling = WhitespaceHandling.None;
         // Parse the file and display each of the nodes.
         bool bResult = reader.Read();
         string outerXML;
         //XDictionaryLoader myDictionaryLoader;
         while (bResult)
         {
             bool bProcessed = false;
             switch (reader.NodeType)
             {
                 case XmlNodeType.Element:
                     string elementName = reader.Name;
                     switch (elementName.ToUpper())
                     {
                         case "IFEVENT": // XEvent
                             outerXML = reader.ReadOuterXml();
                             XTRMEvent thisEvent = (XTRMEvent)XTRMEvent.consumeXML(myConfig, outerXML, 1, true);
                             thisWorkflow.workflowEvents.Add(thisEvent);
                             bProcessed = true;
                             break;
                         // Reset Dictionary!
                         // XConfig
                         case "BASECONFIG":
                             outerXML = reader.ReadOuterXml();
                             //myDictionaryLoader = new XDictionaryLoader();
                             myConfig = new Dictionary<string, string>();
                             myDictionaryLoader.Augment(myConfig, outerXML);
                             bProcessed = true;
                             break;
                         //   Add to the current dictionary!
                         // XConfig
                         case "WITHCONFIG":
                             outerXML = reader.ReadOuterXml();
                             myDictionaryLoader = new XDictionaryLoader();
                             myDictionaryLoader.Augment(myConfig, outerXML);
                             bProcessed = true;
                             break;
                     }
                     if (!bProcessed)
                     {
                         // May wish to get all the  attributes here for new elements!
                         elementAttributes = new Dictionary<String, String>();
                         if (reader.HasAttributes)
                         {
                             reader.MoveToFirstAttribute();
                             for (int i = 0; i < reader.AttributeCount; i++)
                             {
                                 //reader.GetAttribute(i);
                                 elementAttributes.Add(reader.Name, reader.Value);
                                 reader.MoveToNextAttribute();
                             }
                             if (elementAttributes.ContainsKey("Name"))
                             {
                                 // Try to instantiate the XEvent Object!
                                 thisWorkflow.name = elementAttributes["Name"];
                             }
                             if (elementAttributes.ContainsKey("ID"))
                             {
                                 // Try to instantiate the XEvent Object!
                                 thisWorkflow.name = elementAttributes["ID"];
                             }
                             reader.MoveToElement();
                         }
                         // Need to see if we are interested in this element!
                         //string elementName = reader.Name;
                         switch (elementName.ToUpper())
                         {
                             //case "IFEVENT": // XEvent
                             //    outerXML = reader.ReadOuterXml();
                             //    XEvent thisEvent = (XEvent)XEvent.consumeXML(myConfig, outerXML, 1, true);
                             //    thisWorkflow.workflowEvents.Add(thisEvent);
                             //    break;
                             // Reset Dictionary!
                             // XConfig
                             //case "BASECONFIG":
                             //    outerXML = reader.ReadOuterXml();
                             //    //myDictionaryLoader = new XDictionaryLoader();
                             //    myConfig = new Dictionary<string, string>();
                             //    myDictionaryLoader.Augment(myConfig, outerXML);
                             //    break;
                             //   Add to the current dictionary!
                             // XConfig
                             //case "WITHCONFIG":
                             //    outerXML = reader.ReadOuterXml();
                             //    myDictionaryLoader = new XDictionaryLoader();
                             //    myDictionaryLoader.Augment(myConfig, outerXML);
                             //    break;
                             default:
                                 bResult = reader.Read();
                                 break;
                         }
                     }
                     break;
                 case XmlNodeType.XmlDeclaration:
                 case XmlNodeType.ProcessingInstruction:
                     //writer.WriteProcessingInstruction(reader.Name, reader.Value);
                     bResult = reader.Read();
                     break;
                 case XmlNodeType.Comment:
                     //writer.WriteComment(reader.Value);
                     bResult = reader.Read();
                     break;
                 case XmlNodeType.EndElement:
                     //writer.WriteFullEndElement();
                     bResult = reader.Read();
                     break;
                 case XmlNodeType.Text:
                     //Console.Write(reader.Value);
                     switch (lElementType)
                     {
                         //case 1:     // PARMS
                         //    thisTask.parms.Add(reader.Value);
                         default:
                             break;
                     }
                     bResult = reader.Read();
                     break;
                 default:
                     bResult = reader.Read();
                     break;
             }
         }
     }
     catch (Exception ex)
     {
         exCount_XML++;
         XLogger(3100, -1, string.Format("XML={0}; Message={1}", XmlFragment, ex.Message));
     }
     finally
     {
         if (reader != null)
             reader.Close();
     }
     thisWorkflow.config = myConfig;
     return thisWorkflow;
 }
Пример #30
0
        /// <summary>
        /// Load SVG document from a file.
        /// </summary>
        /// <param name="filename">The complete path of a valid SVG file.</param>
        /// <returns>
        ///     True - the file is loaded successfully and it is a valid SVG document
        ///     False - the file cannot be opened or it is not a valid SVG document.
        /// </returns>
        public bool LoadFromFile(string filename)
        {
            if ( svgRoot != null )
            {
                svgRoot = null;
                svgDocumentNextInternalId = 1;
                svgDocumentElements.Clear();
            }

            var result = true;

            try
            {
                var reader = new XmlTextReader(filename)
                {
                    WhitespaceHandling = WhitespaceHandling.None,
                    Normalization = false,
                    XmlResolver = null,
                    Namespaces = false
                };

                SvgElement parentElement = null;

                try
                {
                    // parse the file and display each of the nodes.
                    while ( reader.Read() && result )
                    {
                        switch (reader.NodeType)
                        {
                            case XmlNodeType.Attribute:
                                break;

                            case XmlNodeType.Element:
                                var element = AddElement(parentElement, reader.Name);

                                if ( element != null )
                                {
                                    parentElement = element;

                                    if (reader.IsEmptyElement)
                                    {
                                        if ( parentElement != null )
                                        {
                                            parentElement = parentElement.GetParent();
                                        }
                                    }

                                    var attribute = reader.MoveToFirstAttribute();
                                    while (attribute)
                                    {
                                        element.SetAttributeValue(reader.Name, reader.Value);

                                        attribute = reader.MoveToNextAttribute();
                                    }
                                }

                                break;

                            case XmlNodeType.Text:
                                if ( parentElement != null )
                                {
                                    parentElement.SetElementValue(reader.Value);
                                }
                                break;

                            case XmlNodeType.CDATA:
                                break;

                            case XmlNodeType.ProcessingInstruction:
                                break;

                            case XmlNodeType.Comment:
                                break;

                            case XmlNodeType.XmlDeclaration:
                                svgDocumentXmlDeclaration = "<?xml " + reader.Value + "?>";
                                break;

                            case XmlNodeType.Document:
                                break;

                            case XmlNodeType.DocumentType:
                            {
                                var sDtd1 = reader.GetAttribute("PUBLIC");
                                var sDtd2 = reader.GetAttribute("SYSTEM");

                                svgDocumentXmlDocumentType = "<!DOCTYPE svg PUBLIC \"" + sDtd1 + "\" \"" + sDtd2 + "\">";
                            }
                                break;

                            case XmlNodeType.EntityReference:
                                break;

                            case XmlNodeType.EndElement:
                                if ( parentElement != null )
                                {
                                    parentElement = parentElement.GetParent();
                                }
                                break;
                        } // switch
                    } // while
                } // read try
                catch(XmlException xmle)
                {
                    ErrorMessage =
                        $"{xmle.Message}\r\nLine Number: {xmle.LineNumber.ToString()}\r\nLine Position: {xmle.LinePosition.ToString()}";

                    result = false;
                }
                catch(Exception e)
                {
                    ErrorMessage = e.Message;
                    result = false;
                }
                finally
                {
                    reader.Close();
                }
            }
            catch
            {
                ErrorMessage = "Unhandled Exception";
                result = false;
            }

            return result;
        }
Пример #31
0
        /* Read all el 2a7dees al nabawaya and fill the treeview */
        private void LoadHadeethTree()
        {
            /* Check first if the tree was already loaded*/
            if (trvHadeeth.Nodes.Count > 0) return;

            XmlTextReader xmlReader;
            TreeNode rNode, bNode;

            for (int i = 0; i < 6; i++) {

                /* Check if the file exists first*/
                if (!File.Exists(hadeeth_xml[i])) continue;
                xmlReader = new XmlTextReader(hadeeth_xml[i]);
                xmlReader.ReadToFollowing("kotob");
                rNode = new TreeNode(xmlReader.GetAttribute(0));

                xmlReader.ReadToFollowing("katab");
                do {
                    xmlReader.MoveToFirstAttribute();
                    bNode = new TreeNode(xmlReader.ReadContentAsString());
                    xmlReader.MoveToElement();
                    if (xmlReader.ReadToDescendant("bab")) {
                        /* iterate through el babs in el katab if there are any */
                        do {
                            xmlReader.MoveToAttribute(0);
                            bNode.Nodes.Add(xmlReader.ReadContentAsString());
                        } while (xmlReader.ReadToNextSibling("bab"));
                    }
                    rNode.Nodes.Add(bNode);
                } while (xmlReader.ReadToFollowing("katab"));

                trvHadeeth.Nodes.Add(rNode);

            }
        }