Read() public method

public Read ( ) : bool
return bool
コード例 #1
0
        private void process_constants( XmlNodeReader nodeReader, CompleteTemplate ThisCompleteTemplate )
        {
            // Read all the nodes
            while ( nodeReader.Read() )
            {
                // Get the node name, trimmed and to upper
                string nodeName = nodeReader.Name.Trim().ToUpper();

                // If this is the inputs or constant start tag, return
                if (( nodeReader.NodeType == XmlNodeType.EndElement ) && ( nodeName == "CONSTANTS" ))
                {
                    return;
                }

                // If this is the beginning tag for an element, assign the next values accordingly
                if (( nodeReader.NodeType == XmlNodeType.Element ) && ( nodeName == "ELEMENT" ) && ( nodeReader.HasAttributes ))
                {
                    abstract_Element newConstant = process_element( nodeReader, -1 );
                    if (newConstant != null)
                    {
                        newConstant.isConstant = true;
                        ThisCompleteTemplate.Add_Constant(newConstant);
                    }
                }
            }
        }
コード例 #2
0
ファイル: ValidateXMLFile.cs プロジェクト: neilmayhew/pathway
        public bool ValidateNodeAttribute()
        {
            string propertyValue;
            XmlNodeReader reader;
            bool match = true;

            XmlNode node = Common.GetXmlNode(FileNameWithPath, XPath);

            if (node == null)
            {
                match = false;
            }
            else
            {
                foreach (string propertyKey in ClassProperty.Keys)
                {
                    reader = new XmlNodeReader(node);
                    reader.Read();
                    propertyValue = reader.GetAttribute(propertyKey);
                    if (propertyValue != null && propertyValue != ClassProperty[propertyKey])
                    {
                        match = false;
                    }
                }
            }
            reader = null;
            ClassProperty.Clear();
            return match;
        }
コード例 #3
0
 //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ�
 public bool isSuper(FileInfo obFile, FileInfo obExtends)
 {
     string infoPath = m_obFinder.getClassPath(obExtends.Name.Replace(".as", ""));
     if (File.Exists(infoPath))
     {
         XmlDocument xml = new XmlDocument();
         xml.Load(infoPath);
         XmlNodeReader reader = new XmlNodeReader(xml);
         while (reader.Read())
         {
             if (reader.NodeType == XmlNodeType.Element)
             {
                 if (reader.Name == "item")
                 {
                     string className = reader.GetAttribute("name");
                     string superSign = reader.GetAttribute("super");
                     if (className == obFile.Name.Replace(".as", ""))
                     {
                         if (superSign != null)
                         {
                             reader.Close();
                             //ErrorBox.Show(obExtends.Name + " extends " + obFile.Name,"ClassRelationsFinderError");
                             return true;
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
コード例 #4
0
 private static void move_to_node( XmlNodeReader nodeReader, string nodeName )
 {
     while (( nodeReader.Read() ) && ( nodeReader.Name.Trim() != nodeName ))
     {
         // Do nothing here...
     }
 }
コード例 #5
0
        /// <summary> Reads the item aggregation configuration file and populates the new data into the
        /// item aggregation object </summary>
        /// <param name="HierarchyObject"> Item aggregation object to populate</param>
        /// <param name="FileLocation"> Full name of the item aggregation configuration XML file </param>
        public void Add_Info_From_XML_File(Complete_Item_Aggregation HierarchyObject, string FileLocation )
        {
            // Get the directory from the file location
            string directory = (new FileInfo(FileLocation)).DirectoryName;

            // Load this XML file
            XmlDocument hierarchyXml = new XmlDocument();
            hierarchyXml.Load(FileLocation);

            // create the node reader
            XmlNodeReader nodeReader = new XmlNodeReader(hierarchyXml);

            // Read all the nodes
            while (nodeReader.Read())
            {
                // If this is the beginning tag for an element, assign the next values accordingly
                if (nodeReader.NodeType == XmlNodeType.Element)
                {
                    // Get the node name, trimmed and to upper
                    string nodeName = nodeReader.Name.Trim().ToUpper();

                    // switch the rest based on the tag name
                    switch (nodeName)
                    {
                        case "HI:SETTINGS":
                            read_settings(nodeReader, HierarchyObject);
                            break;

                        case "HI:HOME":
                            read_home(nodeReader, HierarchyObject);
                            break;

                        case "HI:BANNER":
                            read_banners(nodeReader, HierarchyObject);
                            break;

                        case "HI:DIRECTIVES":
                            read_directives(nodeReader, HierarchyObject, directory);
                            break;

                        case "HI:HIGHLIGHTS":
                            read_highlights(nodeReader, HierarchyObject);
                            break;

                        case "HI:BROWSE":
                            read_browse(true, nodeReader, HierarchyObject);
                            break;

                        case "HI:INFO":
                            read_browse(false, nodeReader, HierarchyObject);
                            break;

                        case "HI:RESULTS":
                            read_results_specs(nodeReader, HierarchyObject);
                            break;
                    }
                }
            }
        }
コード例 #6
0
ファイル: Decoder.cs プロジェクト: mayatforest/Refractor
        public object Decode(XmlNodeReader reader)
        {
            if (reader == null) return null;
            _reader = reader;

            if (!_reader.Read()) return null;
            return VisitElement(null, null);
        }
コード例 #7
0
 private static string read_text_node( XmlNodeReader nodeReader )
 {
     if (( nodeReader.Read() ) && ( nodeReader.NodeType == XmlNodeType.Text ))
     {
         return nodeReader.Value.Trim();
     }
     return String.Empty;
 }
コード例 #8
0
ファイル: XmlBackedGraph.cs プロジェクト: emtees/old-code
	Result ReadResult (XmlNode item)
	{
	    string ignored;

	    XmlNodeReader xnr = new XmlNodeReader (item["result"]);
	    xnr.Read (); // no idea why this is needed
			       
	    return Result.ImportXml (xnr, out ignored, log);
	}
コード例 #9
0
		public void ReadFromElement ()
		{
			XmlNodeReader nrdr = new XmlNodeReader (document.DocumentElement);
			nrdr.Read ();
			AssertEquals ("<root>.NodeType", XmlNodeType.Element, nrdr.NodeType);
			AssertEquals ("<root>.Name", "root", nrdr.Name);
			AssertEquals ("<root>.ReadState", ReadState.Interactive, nrdr.ReadState);
			AssertEquals ("<root>.Depth", 0, nrdr.Depth);
		}
コード例 #10
0
ファイル: XmlNodeReaderTests.cs プロジェクト: Profit0004/mono
		public void ReadFromElement ()
		{
			XmlNodeReader nrdr = new XmlNodeReader (document.DocumentElement);
			nrdr.Read ();
			Assert.AreEqual (XmlNodeType.Element, nrdr.NodeType, "<root>.NodeType");
			Assert.AreEqual ("root", nrdr.Name, "<root>.Name");
			Assert.AreEqual (ReadState.Interactive, nrdr.ReadState, "<root>.ReadState");
			Assert.AreEqual (0, nrdr.Depth, "<root>.Depth");
		}
コード例 #11
0
 /// <summary>Factory method for creating a Farm4Prophet object from a file.</summary>
 /// <param name="fileName">The filename of the xml file</param>
 /// <returns>The newly created object.</returns>
 public static Farm4Prophet Farm4ProphetFromFile(string fileName)
 {
     XmlDocument doc = new XmlDocument();
     doc.Load(fileName);
     XmlReader reader = new XmlNodeReader(doc.DocumentElement);
     reader.Read();
     XmlSerializer serial = new XmlSerializer(typeof(Farm4Prophet));
     return (Farm4Prophet)serial.Deserialize(reader);
 }
コード例 #12
0
        /// <summary>
        /// 判断是否为WIN7 以及32或64位
        /// </summary>
        /// <param name="imagex">imagex文件名,默认传imagex字段</param>
        /// <param name="wimfile">WIM文件路径</param>
        /// <returns>不是WIN7系统:0,Windows 7 STARTER(表示为32位系统镜像):1,Windows 7 HOMEBASIC(表示为64位系统镜像):2</returns>
        public static int Iswin7(string imagex, string wimfile)
        {
            ProcessManager.SyncCMD("\"" + WTGModel.applicationFilesPath + "\\" + imagex + "\"" + " /info \"" + wimfile + "\" /xml > " + "\"" + WTGModel.logPath + "\\wiminfo.xml\"");
            XmlDocument xml = new XmlDocument();

            System.Xml.XmlDocument   doc    = new System.Xml.XmlDocument();
            System.Xml.XmlNodeReader reader = null;

            string strFilename = WTGModel.logPath + "\\wiminfo.xml";

            if (!File.Exists(strFilename))
            {
                //MsgManager.getResString("Msg_wiminfoerror")
                //WIM文件信息获取失败\n将按WIN8系统安装
                Log.WriteLog("Iswin7.log", strFilename + "文件不存在");
                //MessageBox.Show(strFilename + MsgManager.getResString("Msg_wiminfoerror", MsgManager.ci));
                return(0);
            }
            try
            {
                doc.Load(strFilename);
                reader = new System.Xml.XmlNodeReader(doc);
                while (reader.Read())
                {
                    if (reader.IsStartElement("NAME"))
                    {
                        //从找到的这个依次往下读取节点
                        System.Xml.XmlNode aa = doc.ReadNode(reader);
                        if (aa.InnerText == "Windows 7 STARTER")
                        {
                            return(1);
                        }
                        else if (aa.InnerText == "Windows 7 HOMEBASIC")
                        {
                            return(2);
                        }
                        else
                        {
                            return(0);
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                Log.WriteLog("Iswin7.log", strFilename + "\n" + ex.ToString());
                //MessageBox.Show(strFilename + MsgManager.getResString("Msg_wiminfoerror", MsgManager.ci) + ex.ToString());
                return(0);
            }



            return(0);
        }
コード例 #13
0
 public object Create(object parent, object configContext, System.Xml.XmlNode section)
 {
     XmlSerializer ser = new XmlSerializer(typeof(TypeResolver));
     TypeResolver config = null;
     using (XmlNodeReader rd = new XmlNodeReader(section.SelectSingleNode("TypeResolver")))
     {
         rd.Read();
         config = (TypeResolver)ser.Deserialize(rd);
     }
     return config;
 }
コード例 #14
0
ファイル: Decoder.cs プロジェクト: mayatforest/Refractor
        public object Decode(string s)
        {
            if (string.IsNullOrEmpty(s)) return null;

            XmlDocument xd = new XmlDocument();
            xd.LoadXml(s);

            _reader = new XmlNodeReader(xd);

            if (!_reader.Read()) return null;
            return VisitElement(null, null);
        }
コード例 #15
0
        private static void read_banners(XmlNodeReader nodeReader, Item_Aggregation hierarchyObject )
        {
            while (nodeReader.Read())
            {
                // If this is the beginning tag for an element, assign the next values accordingly
                if (nodeReader.NodeType == XmlNodeType.Element)
                {
                    // Get the node name, trimmed and to upper
                    string nodeName = nodeReader.Name.Trim().ToUpper();

                    // switch the rest based on the tag name
                    switch (nodeName)
                    {
                        case "HI:SOURCE":
                            // Check for any attributes to this banner node
                            string lang = String.Empty;
                            bool special = false;

                            if (nodeReader.HasAttributes)
                            {

                                if (nodeReader.MoveToAttribute("lang"))
                                {
                                    lang = nodeReader.Value.Trim().ToUpper();
                                }
                                if (nodeReader.MoveToAttribute("type"))
                                {
                                    if (nodeReader.Value.Trim().ToUpper() == "HIGHLIGHT")
                                        special = true;
                                }
                            }

                            // Now read the banner information and add to the aggregation object
                            nodeReader.Read();
                            if (special)
                            {
                                hierarchyObject.Add_Front_Banner_Image(nodeReader.Value, Web_Language_Enum_Converter.Code_To_Enum( lang));
                            }
                            else
                            {
                                hierarchyObject.Add_Banner_Image(nodeReader.Value, Web_Language_Enum_Converter.Code_To_Enum(lang));
                            }

                            break;
                    }
                }

                if ((nodeReader.NodeType == XmlNodeType.EndElement) && (nodeReader.Name.Trim().ToUpper() == "HI:BANNER"))
                {
                    return;
                }
            }
        }
コード例 #16
0
        /*
         * get appx unique flag from Manifest file
         * not completed
        */
        public string GetAppxSignature(string appx)
        {
            string xmlFilePath = this.srcPath + appx + @"\AppxManifest.xml";
            XmlDocument xmldoc = new XmlDocument();
            XmlNodeReader reader = null;

            //string appId = null;
            string platform = null;
            string publisher = null;
            string version = null;
            string name = null;

            try
            {
                xmldoc.Load(xmlFilePath);
                XmlElement root = xmldoc.DocumentElement;
                root = xmldoc.DocumentElement;

                // using Node Reader
                reader = new XmlNodeReader(xmldoc);
                while (reader.Read())
                {
                    if (reader.NodeType.Equals(XmlNodeType.Element)
                        && reader.Name.Equals("Identity"))
                    {
                        platform = reader.GetAttribute("ProcessorArchitecture");
                        publisher = reader.GetAttribute("Publisher");
                        version = reader.GetAttribute("Version");
                        name = reader.GetAttribute("Name");
                        break;
                    }
                    //if (reader.NodeType.Equals(XmlNodeType.Element)
                    //    && reader.Name.Equals("Application"))
                    //{
                    //    appId = reader.GetAttribute("Id");
                    //}
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (null != reader)
                {
                    reader.Close();
                }
            }

            return string.Join("<br>", platform, publisher, version, name);
        }
コード例 #17
0
ファイル: Form1.cs プロジェクト: GPiter/C-Sharp-Courses
        private void BtnGetWeather_Click(object sender, EventArgs e)
        {
            try
            {
                // Используем веб сервис для получения погоды
                var weather = new com.cobbnz.weather.clsWebService();
                // Записываем результат запроса в формат xml
                var str_xml = weather.GetCurrentConditionsAsXML("Saint-Petersburg");
                // Отображаем xml-формат в поле textbox
                tbWeatherInfo.Text = str_xml.ToString();

                // Десериализация полученного xml
                // Создаем объкект типа "XmlDocument"
                var document = new System.Xml.XmlDocument();
                document.LoadXml(str_xml);

                // Создаем объект типа "Чтение узлов xml"
                var reader = new System.Xml.XmlNodeReader(document);
                var name   = String.Empty;
                var temp   = String.Empty;

                // Цикл по узлам xml-документа
                while (reader.Read() == true)
                {
                    // Читаем последовательно каждый узел, выясняя тип узла
                    if (reader.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        name = reader.Name;
                    }

                    // Каждый раз запоминаем имя узла
                    if (reader.NodeType != System.Xml.XmlNodeType.Text)
                    {
                        continue;
                    }

                    // Выход из цикла, когда прочитали данные узла TemperatureCurrent
                    if (name == "TemperatureCurrent")
                    {
                        temp = reader.Value;
                        break;
                    }
                }

                lblCurrentTemp.Text = "Температура: " + temp + " С";
            }

            catch
            {
                MessageBox.Show("Ошибка подключения к веб-службе!", "Внимание!");
            }
        }
コード例 #18
0
        /// <summary>
        /// Checks if the specified <see cref="node"/> starts with the specified <see cref="rootElementTagName"/>
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="rootElementTagName">Name of the root element tag.</param>
        /// <returns><c>true</c> if the specified <see cref="node"/> starts with the specified <see cref="rootElementTagName"/>, <c>false</c> otherwise.</returns>
        public static bool StartsWithElement(this XmlNode node, string rootElementTagName)
        {
            var xmlReader = new XmlNodeReader(node);
            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.Element)
                {
                    return xmlReader.LocalName.Equals(rootElementTagName);
                }
            }

            return false;
        }
コード例 #19
0
ファイル: XmlHelper.cs プロジェクト: qinfengwangyi/Qin.Blog
        /// <summary>
        /// 获取XML
        /// </summary>
        /// <param name="xmlFile"></param>
        /// <returns></returns>
        // xmlFile = HttpContext.Server.MapPath("~/Student.xml")
        public string GetXml(string xmlFile)
        {
            string id = "";
            string Info = "";

            if (XmlDoc == null)
            {
                lock (DocLock)
                {
                    if (XmlDoc == null)
                    {
                        XmlDoc = new XmlDocument();
                        XmlDoc.Load(xmlFile);
                    }
                }
            }

            string Name = string.Empty;
            string _id = string.Empty;
            XmlElement root = XmlDoc.DocumentElement;
            XmlNodeList personNodes = root.GetElementsByTagName("person");
            foreach (XmlNode node in personNodes)
            {
                if (((XmlElement)node).GetAttribute("id") == "2" || ((XmlElement)node).GetAttribute("id") == "4")
                {
                    Name += ((XmlElement)node).InnerText;
                    _id += ((XmlElement)node).GetAttribute("id");
                    var str = node.GetEnumerator();
                }
            }

            XmlNodeReader ParaReader = new XmlNodeReader(XmlDoc);
            while (ParaReader.Read())
            {
                if (ParaReader.NodeType == XmlNodeType.Element && ParaReader.Name == "person")
                {
                    if (!string.IsNullOrEmpty(ParaReader.GetAttribute("id")))
                    {
                        id += ParaReader.GetAttribute("id") + "+";
                        Info += ParaReader.ReadInnerXml() + "+";

                    }
                    //if (f == "PaymentDate" && f == ParaReader.GetAttribute(0)) Info = ParaReader.GetAttribute(1);//Info = ParaReader.GetAttribute(1).Replace("{2}", Member.ValidBeginDate + "");//缴费
                    //if (f == "ReplacementDate" && f == ParaReader.GetAttribute(0)) Info = ParaReader.GetAttribute("value");//Info = ParaReader.GetAttribute("value").Replace("{2}", Member.ValidBeginDate + "").Replace("{3}", Member.ReplacementDate + "");  //换证 
                    //if (f == "ContributionsDate" && f == ParaReader.GetAttribute(0)) Info = ParaReader.GetAttribute("value"); //体检 
                }
                string str = ParaReader.GetAttribute("id") + ParaReader.GetAttribute("sex") + ParaReader.ReadInnerXml();
            }
            ParaReader.Close();
            return System.Text.Encoding.GetEncoding("gb2312").GetString(System.Text.Encoding.Default.GetBytes(id + "\n" + Info));
        }
コード例 #20
0
ファイル: DataConnection.cs プロジェクト: mnisl/OD
		///<summary></summary>
		private string GetOpenDentalConnStr() {
			XmlDocument document=new XmlDocument();
			string path=ODFileUtils.CombinePaths(Application.StartupPath,"FreeDentalConfig.xml");
			if(!File.Exists(path)) {
				return "";
			}
			string computerName="";
			string database="";
			string user="";
			string password="";
			try {
				document.Load(path);
				XmlNodeReader reader=new XmlNodeReader(document);
				string currentElement="";
				while(reader.Read()) {
					if(reader.NodeType==XmlNodeType.Element) {
						currentElement=reader.Name;
					}
					else if(reader.NodeType==XmlNodeType.Text) {
						switch(currentElement) {
							case "ComputerName":
								computerName=reader.Value;
								break;
							case "Database":
								database=reader.Value;
								break;
							case "User":
								user=reader.Value;
								break;
							case "Password":
								password=reader.Value;
								break;
						}
					}
				}
				reader.Close();
			}
			catch {
				return "";
			}
			//example:
			//Server=localhost;Database=opendental;User ID=root;Password=;CharSet=utf8
			return "Server="+computerName
				+";Database="+database
				+";User ID="+user
				+";Password="******";CharSet=utf8";
		}
コード例 #21
0
		private void FormDatabaseCheck_Load(object sender,EventArgs e) {
			XmlDocument document=new XmlDocument();
			if(!File.Exists("FreeDentalConfig.xml")) {
				textComputerName.Text="localhost";
				#if(TRIALONLY)
					textDatabase.Text="demo";
				#else
					textDatabase.Text="opendental";
				#endif
				textUser.Text="root";
				return;
			}
			try {
				document.Load("FreeDentalConfig.xml");
				XmlNodeReader reader=new XmlNodeReader(document);
				string currentElement="";
				while(reader.Read()) {
					if(reader.NodeType==XmlNodeType.Element) {
						currentElement=reader.Name;
					}
					else if(reader.NodeType==XmlNodeType.Text) {
						switch(currentElement) {
							case "ComputerName":
								textComputerName.Text=reader.Value;
								break;
							case "Database":
								textDatabase.Text=reader.Value;
								break;
							case "User":
								textUser.Text=reader.Value;
								break;
							case "Password":
								textPassword.Text=reader.Value;
								break;
						}
					}
				}
				reader.Close();
			}
			catch {//Exception e) {
				//MessageBox.Show(e.Message);
				textComputerName.Text="localhost";
				textDatabase.Text="opendental";
				textUser.Text="root";
			}
		}
コード例 #22
0
 public virtual XmlConfigElt ValueAt(string xPath)
 {
     if (XmlDoc == null)
     {
         return(new XmlConfigElt(xPath, null));
     }
     lock (typeof(XmlConfig)) {
         System.Xml.XmlNode node = XmlDoc.SelectSingleNode(xPath);
         if (node == null)
         {
             return(new XmlConfigElt(xPath, null));
         }
         System.Xml.XmlNodeReader nodeReader = new System.Xml.XmlNodeReader(node);
         nodeReader.Read();
         return(new XmlConfigElt(xPath, nodeReader.ReadElementString()));
     }
 }
コード例 #23
0
        static void Main(string[] args)
        {
            var artists = new List<string>();
            var albums = new List<string>();

            var catalogFilePath = "../../../../catalog.xml";
            XmlDocument doc = new XmlDocument();
            doc.Load(catalogFilePath);
            using (XmlNodeReader reader = new XmlNodeReader(doc))
            {
                reader.MoveToContent();
                reader.ReadToDescendant("album");

                while (reader.Read())
                {
                    var albumName = reader.ReadInnerXml();
                    albums.Add(albumName);

                    var artist = reader.ReadInnerXml();
                    artists.Add(artist);

                    reader.ReadToFollowing("album");
                }
            }

            string albumFilePath = "../../album.xml";
            Encoding encoding = Encoding.GetEncoding("windows-1251");
            using (XmlTextWriter writer = new XmlTextWriter(albumFilePath, encoding))
            {
                writer.Formatting = Formatting.Indented;
                writer.IndentChar = '\t';
                writer.Indentation = 1;

                writer.WriteStartDocument();
                writer.WriteStartElement("albums");
                for (int i = 0, len = artists.Count; i < len; i++)
                {
                    WriteAlbum(writer, albums[i], artists[i]);
                }
                writer.WriteEndDocument();
            }

            Console.WriteLine("Document {0} created.", albumFilePath);
        }
コード例 #24
0
		///<summary></summary>
		private string GetConnectionString(){
			XmlDocument document=new XmlDocument();
			string configFile=ODFileUtils.CombinePaths(new string[] {"..","..","..","OpenDental","bin","Release","FreeDentalConfig.xml"} );
			if(!File.Exists(configFile)){
				MessageBox.Show(configFile+" does not exist.");
				Application.Exit();
				return "";
			}
			document.Load(configFile);
			XmlNodeReader reader=new XmlNodeReader(document);
			string currentElement="";
			string ComputerName="";
			string Database="";
			string DbUser="";
			string Password="";
			while(reader.Read()) {
				if(reader.NodeType==XmlNodeType.Element) {
					currentElement=reader.Name;
				}
				else if(reader.NodeType==XmlNodeType.Text) {
					switch(currentElement) {
						case "ComputerName":
							ComputerName=reader.Value;
							break;
						case "Database":
							Database=reader.Value;
							break;
						case "User":
							DbUser=reader.Value;
							break;
						case "Password":
							Password=reader.Value;
							break;
					}
				}
			}
			reader.Close();
			return "Server="+ComputerName
				+";Database="+Database
				+";User ID="+DbUser
				+";Password="******";CharSet=utf8";
		}
コード例 #25
0
ファイル: XmlNodeReaderTests.cs プロジェクト: Profit0004/mono
		public void InvalidConstruction ()
		{
			XmlNodeReader nrdr;
			try {
				nrdr = new XmlNodeReader (null);
				Assert.Fail ("ArgumentNullException is expected.");
			} catch (ArgumentNullException) {
			}
			nrdr = new XmlNodeReader (new XmlDocument ());
			nrdr.Read ();
			Assert.AreEqual (ReadState.Error, nrdr.ReadState, "newDoc.ReadState");
			Assert.AreEqual (true, nrdr.EOF, "newDoc.EOF");
			Assert.AreEqual (XmlNodeType.None, nrdr.NodeType, "newDoc.NodeType");
			nrdr = new XmlNodeReader (document.CreateDocumentFragment ());
			nrdr.Read ();
			Assert.AreEqual (ReadState.Error, nrdr.ReadState, "Fragment.ReadState");
			Assert.AreEqual (true, nrdr.EOF, "Fragment.EOF");
			Assert.AreEqual (XmlNodeType.None, nrdr.NodeType, "Fragment.NodeType");
		}
コード例 #26
0
		public void InvalidConstruction ()
		{
			XmlNodeReader nrdr;
			try {
				nrdr = new XmlNodeReader (null);
				Fail ("null reference exception is preferable.");
			} catch (NullReferenceException) {
			}
			nrdr = new XmlNodeReader (new XmlDocument ());
			nrdr.Read ();
			AssertEquals ("newDoc.ReadState", ReadState.Error, nrdr.ReadState);
			AssertEquals ("newDoc.EOF", true, nrdr.EOF);
			AssertEquals ("newDoc.NodeType", XmlNodeType.None, nrdr.NodeType);
			nrdr = new XmlNodeReader (document.CreateDocumentFragment ());
			nrdr.Read ();
			AssertEquals ("Fragment.ReadState", ReadState.Error, nrdr.ReadState);
			AssertEquals ("Fragment.EOF", true, nrdr.EOF);
			AssertEquals ("Fragment.NodeType", XmlNodeType.None, nrdr.NodeType);
		}
コード例 #27
0
		public virtual NvdlValidatorGenerator CreateGenerator (NvdlValidate validate, string schemaType, NvdlConfig config)
		{
			this.validate = validate;
			this.schema_type = schemaType;
			this.config = config;

			XmlReader schema = null;
			// FIXME: we need a bit more strict check.
			if (schemaType.Length < 5 ||
				!schemaType.EndsWith ("xml") ||
				Char.IsLetter (schemaType, schemaType.Length - 4))
				return null;

			string schemaUri = validate.SchemaUri;
			XmlElement schemaBody = validate.SchemaBody;

			if (schemaUri != null) {
				if (schemaBody != null)
					throw new NvdlCompileException ("Both 'schema' attribute and 'schema' element are specified in a 'validate' element.", validate);
				schema = GetSchemaXmlStream (schemaUri, config, validate);
			}
			else if (validate.SchemaBody != null) {
				XmlReader r = new XmlNodeReader (schemaBody);
				r.MoveToContent ();
				r.Read (); // Skip "schema" element
				r.MoveToContent ();
				if (r.NodeType == XmlNodeType.Element)
					schema = r;
				else
					schema = GetSchemaXmlStream (r.ReadString (), config, validate);
			}

			if (schema == null)
				return null;

			return CreateGenerator (schema, config);
		}
コード例 #28
0
ファイル: entrylink.cs プロジェクト: mintwans/cpsc483
        /////////////////////////////////////////////////////////////////////////////


        #region EntryLink Parser
        //////////////////////////////////////////////////////////////////////
        /// <summary>parses an xml node to create an EntryLink object</summary> 
        /// <param name="node">entrylink node</param>
        /// <param name="parser">AtomFeedParser to use</param>
        /// <returns> the created EntryLink object</returns>
        //////////////////////////////////////////////////////////////////////
        public static EntryLink ParseEntryLink(XmlNode node, AtomFeedParser parser)
        {
            Tracing.TraceCall();
            EntryLink link = null;
            Tracing.Assert(node != null, "node should not be null");
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            

            object localname = node.LocalName;
            if (localname.Equals(GDataParserNameTable.XmlEntryLinkElement))
            {
                link = new EntryLink();
                if (node.Attributes != null)
                {
                    if (node.Attributes[GDataParserNameTable.XmlAttributeHref] != null)
                    {
                        link.Href = node.Attributes[GDataParserNameTable.XmlAttributeHref].Value;
                    }

                    if (node.Attributes[GDataParserNameTable.XmlAttributeReadOnly] != null)
                    {
                        link.ReadOnly = node.Attributes[GDataParserNameTable.XmlAttributeReadOnly].Value.Equals(Utilities.XSDTrue);
                    }

                    if (node.Attributes[GDataParserNameTable.XmlAttributeRel] != null)
                    {
                        link.Rel = node.Attributes[GDataParserNameTable.XmlAttributeRel].Value;
                    }

                }

                if (node.HasChildNodes)
                {
                    XmlNode entryChild = node.FirstChild;

                    while (entryChild != null && entryChild is XmlElement)
                    {
                        if (entryChild.LocalName == AtomParserNameTable.XmlAtomEntryElement &&
                            entryChild.NamespaceURI == BaseNameTable.NSAtom)
                        {

                            if (link.Entry == null)
                            {
                                XmlReader reader = new XmlNodeReader(entryChild);
                                // move the reader to the first node
                                reader.Read();
                                parser.NewAtomEntry += new FeedParserEventHandler(link.OnParsedNewEntry); 
                                parser.ParseEntry(reader); 
                            }
                            else
                            {
                                throw new ArgumentException("Only one entry is allowed inside the g:entryLink");
                            }
                        }
                        entryChild = entryChild.NextSibling;
                    }
                }

            }

            return link;
        }
コード例 #29
0
ファイル: XmlNodeReaderTests.cs プロジェクト: Profit0004/mono
		public void ResolveEntity ()
		{
			string ent1 = "<!ENTITY ent 'entity string'>";
			string ent2 = "<!ENTITY ent2 '<foo/><foo/>'>]>";
			string dtd = "<!DOCTYPE root[<!ELEMENT root (#PCDATA|foo)*>" + ent1 + ent2;
			string xml = dtd + "<root>&ent;&ent2;</root>";
			document.LoadXml (xml);
			Assert.AreEqual (xml, document.OuterXml);
			XmlNodeReader nr = new XmlNodeReader (document);
			nr.Read ();	// DTD
			nr.Read ();	// root
			nr.Read ();	// &ent;
			Assert.AreEqual (XmlNodeType.EntityReference, nr.NodeType);
			Assert.AreEqual (1, nr.Depth, "depth#1");
			nr.ResolveEntity ();
			// It is still entity reference.
			Assert.AreEqual (XmlNodeType.EntityReference, nr.NodeType);
			nr.Read ();
			Assert.AreEqual (XmlNodeType.Text, nr.NodeType);
			Assert.AreEqual (2, nr.Depth, "depth#2");
			Assert.AreEqual ("entity string", nr.Value);
			nr.Read ();
			Assert.AreEqual (XmlNodeType.EndEntity, nr.NodeType);
			Assert.AreEqual (1, nr.Depth, "depth#3");
			Assert.AreEqual ("", nr.Value);

			nr.Read ();	// &ent2;
			Assert.AreEqual (XmlNodeType.EntityReference, nr.NodeType);
			Assert.AreEqual (1, nr.Depth, "depth#4");
			nr.ResolveEntity ();
			Assert.AreEqual (xml, document.OuterXml);
			// It is still entity reference.
			Assert.AreEqual (XmlNodeType.EntityReference, nr.NodeType);
			// It now became element node.
			nr.Read ();
			Assert.AreEqual (XmlNodeType.Element, nr.NodeType);
			Assert.AreEqual (2, nr.Depth, "depth#5");

			Assert.AreEqual (xml, document.OuterXml);
		}
コード例 #30
0
ファイル: XmlNodeReaderTests.cs プロジェクト: Profit0004/mono
		[Test] // bug #550379
		public void MoveToNextAttributeFromValue ()
		{
			document.LoadXml ("<ul test='xxx'></ul>");
			XmlNodeReader nr = new XmlNodeReader (document);
			nr.Read ();
			//nr.Read (); // why twice?
			Assert.IsTrue (nr.MoveToFirstAttribute (), "#1");
			Assert.IsTrue (nr.ReadAttributeValue (), "#2");
			Assert.IsFalse (nr.MoveToNextAttribute (), "#3");
		}
コード例 #31
0
ファイル: Form1.cs プロジェクト: xpoi5010/TimeTable
        //Add:1.0.1.0
        public EventInfo[] LoadXML(string path)
        {
            System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
            SavePath = path;
            xd.Load(SavePath);
            System.Xml.XmlNodeReader xnr = new System.Xml.XmlNodeReader(xd);
            string           Time        = "";
            string           element     = "";
            bool             IsEvent     = false;
            EventInfo        temp        = new EventInfo();
            string           start       = "";
            string           week        = "";
            List <EventInfo> output      = new List <EventInfo>();

            while (xnr.Read())
            {
                switch (xnr.NodeType)
                {
                case (XmlNodeType.Element):
                    element = xnr.Name;
                    switch (element)
                    {
                    case ("Timetable"):
                        start = xnr.GetAttribute("start");
                        string[] split = System.Text.RegularExpressions.Regex.Split(start, ",");
                        dateSelecter1.Year  = Convert.ToInt32(split[0]);
                        dateSelecter1.Month = Convert.ToInt32(split[1]);
                        dateSelecter1.Day   = Convert.ToInt32(split[2]);
                        break;

                    case ("Event"):
                        IsEvent = true;
                        week    = "";
                        start   = "";
                        temp    = new EventInfo();
                        break;

                    case ("Time"):
                        Time = xnr.GetAttribute("time");
                        break;

                    case ("Repeat"):
                        week = xnr.GetAttribute("week");

                        break;
                    }
                    break;

                case (XmlNodeType.Text):
                    if (IsEvent)
                    {
                        if (element == "Name")
                        {
                            temp.starttime = new Time(Time);
                            temp.EventName = xnr.Value;
                        }
                        else if (element == "Repeat")
                        {
                            string[] Split = System.Text.RegularExpressions.Regex.Split(xnr.Value, ":");
                            int[]    w_    = Array.ConvertAll(Split, item => Convert.ToInt32(item));
                            if (week == "" || week == null)
                            {
                                temp.Repeat_OneWeek  = w_;
                                temp.Repeat_Biweekly = temp.Repeat_OneWeek;
                            }
                            if (week == "1")
                            {
                                temp.Repeat_OneWeek = w_;
                            }
                            if (week == "2")
                            {
                                temp.Repeat_Biweekly = w_;
                            }
                        }
                    }
                    break;

                case (XmlNodeType.EndElement):
                    switch (xnr.Name)
                    {
                    case ("Event"):
                        IsEvent = false;
                        output.Add(temp);
                        temp = new EventInfo();
                        break;
                    }
                    break;
                }
            }
            xnr.Close();
            return(output.ToArray());
        }
コード例 #32
0
 //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡζ˿ڶ�ȡ����
 private void readServerConfig()
 {
     XmlDocument xml = new XmlDocument();
     string filePath = m_stHostConfig;
     if (File.Exists(filePath))
     {
         FileStream fs = new FileStream(filePath, FileMode.Open);
         try
         {
             xml.Load(fs);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString());
         }
         XmlNode subXml = HxmlReader.getData(xml);
         if (subXml != null)
         {
             XmlNodeReader reader = new XmlNodeReader(subXml);
             while (reader.Read())
             {
                 if (reader.NodeType == XmlNodeType.Element)
                 {
                     if (reader.Name == "host")
                     {
                         string stName = reader.GetAttribute("name");
                         if (stName != null)
                         {
                             s_stHostName = stName;
                         }
                         string stIp = reader.GetAttribute("ip");
                         if (stIp != null)
                         {
                             s_stHostIp = stIp;
                         }
                         string stPort = reader.GetAttribute("port");
                         if (stPort != null)
                         {
                             s_nHostPort = int.Parse(stPort);
                         }
                     }
                 }
             }
             fs.Close();
         }
     }
 }
コード例 #33
0
 /// <summary>
 /// This removes namespaces from an XML Element (Scott)
 /// </summary>
 /// <param name="xeElement"></param>
 /// <returns></returns>
 protected string RemoveNamespaces(XmlNode xeElement)
 {
     StringWriter swOutput = new System.IO.StringWriter();
     XmlTextWriter xtwWriter = new XmlTextWriter(swOutput);
     //xtwWriter.WriteStartDocument();
     XmlNodeReader xnrReader = new XmlNodeReader(xeElement);
     while (xnrReader.Read())
     {
         switch (xnrReader.NodeType)
         {
             case XmlNodeType.Element:
                 xtwWriter.WriteStartElement(xnrReader.Name);
                 if (xnrReader.HasAttributes)
                 {
                     while (xnrReader.MoveToNextAttribute())
                     {
                         if (xnrReader.Name != "xmlns")
                         {
                             xtwWriter.WriteAttributeString(xnrReader.Name, xnrReader.Value);
                         }
                     }
                     xnrReader.MoveToElement();
                 }
                 if (xnrReader.IsEmptyElement)
                 {
                     xtwWriter.WriteEndElement();
                 }
                 break;
             case XmlNodeType.Text:
                 xtwWriter.WriteString(xnrReader.Value);
                 break;
             case XmlNodeType.CDATA:
                 xtwWriter.WriteCData(xnrReader.Value);
                 break;
             case XmlNodeType.ProcessingInstruction:
                 xtwWriter.WriteProcessingInstruction(xnrReader.Name, xnrReader.Value);
                 break;
             case XmlNodeType.Comment:
                 xtwWriter.WriteComment(xnrReader.Value);
                 break;
             case XmlNodeType.EntityReference:
                 xtwWriter.WriteEntityRef(xnrReader.Name);
                 break;
             case XmlNodeType.EndElement:
                 xtwWriter.WriteEndElement();
                 break;
         }
     }
     //xtwWriter.WriteEndDocument();
     xtwWriter.Flush();
     xtwWriter.Close();
     xnrReader.Close();
     string sOutput = swOutput.ToString();
     return sOutput;
 }
コード例 #34
0
ファイル: XmlNodeReaderTests.cs プロジェクト: Profit0004/mono
		[Test] // bug #76260
		public void FromEmptyNonDocumentElement ()
		{
			document.LoadXml ("<root><child/></root>");
			XmlNodeReader nr = new XmlNodeReader (
				document.DocumentElement.FirstChild);
			nr.Read ();
			Assert.AreEqual (true, nr.IsEmptyElement, "#0");
			Assert.IsTrue (!nr.Read (), "#1");

			document.LoadXml ("<root><child></child></root>");
			nr = new XmlNodeReader (
				document.DocumentElement.FirstChild);
			nr.Read ();
			Assert.IsTrue (nr.Read (), "#2");
			Assert.AreEqual (false, nr.IsEmptyElement, "#2.2");
			Assert.IsTrue (!nr.Read (), "#3");
		}