当前位置: 首页>>代码示例>>C#>>正文


C# XmlTextReader.Close方法代码示例

本文整理汇总了C#中XmlTextReader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.Close方法的具体用法?C# XmlTextReader.Close怎么用?C# XmlTextReader.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XmlTextReader的用法示例。


在下文中一共展示了XmlTextReader.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadXML

	private void ReadXML()
	{
		string xmlFile = Server.MapPath("DvdList.xml");

		// Create the reader.
		XmlTextReader reader = new XmlTextReader(xmlFile);

		StringBuilder str = new StringBuilder();
		reader.ReadStartElement("DvdList");

		// Read all the <DVD> elements.
		while (reader.Read())
		{
			if ((reader.Name == "DVD") && (reader.NodeType == XmlNodeType.Element))
			{
				reader.ReadStartElement("DVD");
				str.Append("<ul><b>");
				str.Append(reader.ReadElementString("Title"));
				str.Append("</b><li>");
				str.Append(reader.ReadElementString("Director"));
				str.Append("</li><li>");
				str.Append(String.Format("{0:C}",
					Decimal.Parse(reader.ReadElementString("Price"))));
				str.Append("</li></ul>");
			}
		}
		// Close the reader and show the text.
		reader.Close();
		XmlText.Text = str.ToString();
	}
开发者ID:Helen1987,项目名称:edu,代码行数:30,代码来源:ReadXmlEfficient.aspx.cs

示例2: ReadXml

    public static List<string> ReadXml(string path, string colum)
    {
        List<string> listOfElements = new List<string>();

        XmlTextReader textReader = new XmlTextReader(path);

        int foundName = 0;

        while (textReader.Read())
        {
            if (foundName > 0 && textReader.Name != string.Empty && !String.Equals(textReader.Name, colum, StringComparison.CurrentCultureIgnoreCase))
                foundName = 0;

            if (foundName == 2 && String.Equals(textReader.Name, colum, StringComparison.CurrentCultureIgnoreCase))
            {
                foundName = 0; continue;
            }

            if (foundName == 0 && String.Equals(textReader.Name, colum, StringComparison.CurrentCultureIgnoreCase))
            {
                foundName = 1; continue;
            }

            if (foundName != 1 || textReader.Name != string.Empty) continue;

            listOfElements.Add(textReader.Value);
        }

        textReader.Close();
        return listOfElements;
    }
开发者ID:nelsonjma,项目名称:siebel_log_notepad,代码行数:31,代码来源:read_xml.cs

示例3: Main

  static void Main(string[] args)
  {
    string localURL = @"http://ip-address.domaintools.com/myip.xml";
    XmlTextReader xmlreader = null;
    xmlreader = new XmlTextReader (localURL);

    while (xmlreader.Read())
    {
    
    	if(xmlreader.NodeType == XmlNodeType.Element)
    	{
    	
    			Console.WriteLine("Element : " + xmlreader.Name);
    
    	} 

    	if(xmlreader.NodeType == XmlNodeType.Text)
    	{
    		Console.WriteLine("Value : " +xmlreader.Value);
    	}
    }
    if (xmlreader != null)
      xmlreader.Close();

  }
开发者ID:EdiCarlos,项目名称:MyPractices,代码行数:25,代码来源:example1.cs

示例4: Button1_ServerClick

 protected void Button1_ServerClick(object sender, EventArgs e)
 {
     try
     {
         string currency = idChoice.Value;
         XmlDocument doc = new XmlDocument();
         string url = Server.MapPath("../data/xml/configproduct.xml");
         XmlTextReader reader = new XmlTextReader(url);
         doc.Load(reader);
         reader.Close();
         if (doc.IsReadOnly)
         {
             diverr.Visible = true;
             diverr.InnerHtml = "File XML đã bị khóa. Không thể thay đổi";
             return;
         }
         XmlNode nodeEdit = doc.SelectSingleNode("root/product[nameappunit='currency']/unit");
         string value = nodeEdit.InnerText;
         if (!value.Equals(currency))
         {
             nodeEdit.InnerText = currency;
             doc.Save(url);
             Application["currency"] = currency;
             diverr.Visible = true;
             diverr.InnerHtml = "Đã thay đổi cách hiển thị tiền tệ";
         }
         else
         {
             diverr.Visible = true;
             diverr.InnerHtml = "Hệ thống đang hiển thị kiểu tiền này.";
         }
     }catch
     {}
 }
开发者ID:BGCX261,项目名称:zlap-svn-to-git,代码行数:34,代码来源:ChangeCurrency.ascx.cs

示例5: SetAppTypeProduct

    public void SetAppTypeProduct()
    {
        try
        {
            XmlDocument doc = new XmlDocument();
            string xpath = Server.MapPath("../data/xml/configproduct.xml");
            XmlTextReader reader = new XmlTextReader(xpath);
            doc.Load(reader);
            reader.Close();
            XmlNodeList nodes = doc.SelectNodes("/root/product");
            int numnodes = nodes.Count;
            for (int i = 0; i < numnodes; i++)
            {
                string nameapp = nodes.Item(i).ChildNodes[0].InnerText;
                string idtype = nodes.Item(i).ChildNodes[1].InnerText;
                string appunit = nodes.Item(i).ChildNodes[2].InnerText;
                string unit = nodes.Item(i).ChildNodes[3].InnerText;
                if (nameapp.Length > 0 && idtype.Length > 0)
                {
                    Application[nameapp] = int.Parse(idtype);
                }
                if (appunit.Length > 0 && unit.Length > 0)
                {
                    Application[appunit] = unit;
                }
            }
        }
        catch
        {

        }
    }
开发者ID:BGCX261,项目名称:zlap-svn-to-git,代码行数:32,代码来源:AdminWebsite.aspx.cs

示例6: ReadXml

    private static string ReadXml(string filename, int ID)
    {
        string strLastVersion = "";

        XmlTextReader reader = new XmlTextReader(filename);

        while (reader.Read())
        {
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.Name == "id")
                    {
                        if (reader.Value == ID.ToString())
                        {
                            strLastVersion = reader.ReadString();
                            reader.Close();
                            return strLastVersion;
                        }
                    }
                }
            }
        }

        return strLastVersion;
    }
开发者ID:Suplanus,项目名称:EplanElectricP8Automatisieren,代码行数:27,代码来源:02_XML-Datei_lesen.cs

示例7: GetTargetNamespace

	public static string GetTargetNamespace (string src)
	{
		XmlTextReader reader = null;
		try
		{
			reader = new XmlTextReader (src);
			reader.WhitespaceHandling = WhitespaceHandling.None;
			while (reader.Read())
			{
				if (reader.NodeType == XmlNodeType.Element &&
				reader.LocalName == "schema")
				{
					while (reader.MoveToNextAttribute ())
					{
						if (reader.Name == "targetNamespace")
							return reader.Value;
					}
				}
			}
			return "";
		}	
		finally 
		{
			if (reader != null)
				reader.Close ();
		}
	}
开发者ID:xs2ranjeet,项目名称:13ns9-1spr,代码行数:27,代码来源:Program.cs

示例8: GetDialogById

    public List<string> GetDialogById(string id)
    {
        XmlTextReader reader = new XmlTextReader(XMLFileName);
        List<string> texts   = new List<string>();

        while (reader.Read())
        {
            if (reader.NodeType == XmlNodeType.Element && reader.Name == id)
            {
                int i = 0;
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.EndElement && reader.Name == id)
                    {
                        break;
                    }
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == ("text_" + i))
                    {
                        texts.Add(reader.ReadElementContentAsString());
                        i++;
                    }
                }
            }
        }
        reader.Close();

        return texts;
    }
开发者ID:AlexanderMekumyanov,项目名称:SerKnight,代码行数:28,代码来源:DialogSystem.cs

示例9: Main

	static void Main (string [] args)
	{
		string schemaFile = "bug.xsd";
		XmlTextReader treader = new XmlTextReader (schemaFile);

		XmlSchema sc = XmlSchema.Read (treader, null);
		sc.Compile (null);

		string page =
			"<body xmlns=\"" + sc.TargetNamespace + "\">"
			+ "<div>"
			+ "</div>"
			+ "</body>";

		System.Xml.XmlTextReader reader = new XmlTextReader (new StringReader (page));
		try {
			XmlValidatingReader validator = new System.Xml.XmlValidatingReader (reader);
			validator.Schemas.Add (sc);
			validator.ValidationType = ValidationType.Schema;
			validator.EntityHandling = EntityHandling.ExpandCharEntities;
			while (validator.Read ()) {
			}
		} finally {
			reader.Close ();
		}
	}
开发者ID:mono,项目名称:gert,代码行数:26,代码来源:test.cs

示例10: RunTest

	static void RunTest ()
	{
		foreach (DirectoryInfo di in new DirectoryInfo (@"relax-ng").GetDirectories ()) {
			XmlTextReader xtr = null;
			FileInfo fi = new FileInfo (di.FullName + "/i.rng");
			// Invalid grammar case:
			if (fi.Exists) {
				xtr = new XmlTextReader (fi.FullName);
				try {
					RelaxngPattern.Read (xtr).Compile ();
					Console.WriteLine ("Expected error: " + di.Name);
				} catch (RelaxngException ex) {
				} catch (XmlException ex) {
				} catch (ArgumentNullException ex) {
				} catch (UriFormatException ex) {
				} catch (Exception ex) {
					Console.WriteLine ("Unexpected error type : " + di.Name + " : " + ex.Message);
				} finally {
					xtr.Close ();
				}
				continue;
			}

			// Valid grammar case:
			xtr = new XmlTextReader (di.FullName + "/c.rng");
			RelaxngPattern p = null;
			try {
				p = RelaxngPattern.Read (xtr);
				p.Compile ();
				} catch (Exception ex) {
					Console.WriteLine ("Invalidated grammar: " + di.Name + " : " + ex.Message);
					continue;
			} finally {
				xtr.Close ();
			}


			// Instance validation
			foreach (FileInfo inst in di.GetFiles ("*.xml")) {
				try {
					RelaxngValidatingReader vr = new RelaxngValidatingReader (new XmlTextReader (inst.FullName), p);
					if (skip_error)
						vr.InvalidNodeFound += RelaxngValidatingReader.IgnoreError;
					while (!vr.EOF)
						vr.Read ();
					if (inst.Name.IndexOf ("i.") >= 0 && !skip_error)
						Console.WriteLine ("Incorrectly validated instance: " + di.Name + "/" + inst.Name);
				} catch (RelaxngException ex) {
					string path = di.Name + "/" + inst.Name;
					if (skip_error)
						Console.WriteLine ("Failed to skip error : " + path + ex.Message);
					if (inst.Name.IndexOf ("i.") >= 0)
						continue;
					Console.WriteLine ("Invalidated instance: " + path + " : " + ex.Message);
				}
			}
		}
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:58,代码来源:relaxngtest.cs

示例11: Load

    public static CBWProcessor Load(string filename)
    {
        XmlTextReader reader = new XmlTextReader (filename);
        XmlDocument doc = new XmlDocument ();

        doc.Load (reader);
        reader.Close ();

        XmlNode root = doc.DocumentElement;

        if (root.Name != "bw")
            throw new ApplicationException ("Wrong root node");

        XmlNode node = root.FirstChild;
        if (node.Name != "load")
            throw new ApplicationException ("Could not find load node");
        CBWProcessor processor = new CBWProcessor (node.InnerText);

        node = node.NextSibling;
        if (node.Name != "mixer")
            throw new ApplicationException ("Could not find mixer node");

        processor.Red = (float)Double.Parse (node.Attributes.GetNamedItem ("red").Value);
        processor.Green = (float)Double.Parse (node.Attributes.GetNamedItem ("green").Value);
        processor.Blue = (float)Double.Parse (node.Attributes.GetNamedItem ("blue").Value);

        node = node.NextSibling;
        if (node.Name != "contrast")
            throw new ApplicationException ("Could not find contrast node");

        Curve curve = processor.ContrastCurve;
        while (curve.NumPoints () > 0)
            curve.RemovePointIndex (0);

        XmlNode curveNode = node.FirstChild;
        if (curveNode.Name != "curve")
            throw new ApplicationException ("Could not find curve node");
        curveNode = curveNode.FirstChild;
        while (curveNode != null) {
            if (curveNode.Name != "point")
                throw new ApplicationException ("Could not find point node");

            curve.AddPoint ((float)Double.Parse (curveNode.Attributes.GetNamedItem ("x").Value),
                            (float)Double.Parse (curveNode.Attributes.GetNamedItem ("y").Value));

            curveNode = curveNode.NextSibling;
        }

        node = node.NextSibling;
        if (node.Name != "tint")
            throw new ApplicationException ("Could not find tint node");

        processor.TintHue = (float)Double.Parse (node.Attributes.GetNamedItem ("hue").Value);
        processor.TintAmount = (float)Double.Parse (node.Attributes.GetNamedItem ("amount").Value);

        return processor;
    }
开发者ID:schani,项目名称:bwprocessor,代码行数:57,代码来源:CBWProcessor.cs

示例12: DeserializeStringToObject

    public static Levels DeserializeStringToObject(TextAsset xmlTextAsset)
    {
        MemoryStream memStream = new MemoryStream (xmlTextAsset.bytes);
        XmlTextReader xmlReader = new XmlTextReader (memStream);
        var serializer = new XmlSerializer (typeof(Levels));
        Levels lvl = serializer.Deserialize (xmlReader) as Levels;

        xmlReader.Close ();
        memStream.Close ();

        return lvl;
    }
开发者ID:rokr047,项目名称:UNITYHelper,代码行数:12,代码来源:Levels.cs

示例13: LoadItems

    public bool LoadItems()
    {
        Item item = null;

        if(File.Exists(file))
        {
            XmlTextReader reader = new XmlTextReader(file);
            while(reader.Read())
            {
                switch(reader.Name.ToString().ToLower())
                {
                    case "item": //assuming there is more than one item
                        item = new Item();
                        if(reader.HasAttributes)
                        {
                            while(reader.MoveToNextAttribute())
                            {
                                switch(reader.Name.ToString().ToLower())
                                {
                                    case "id":
                                        item.id = Convert.ToInt32(reader.Value);
                                        break;
                                    case "name":
                                        item.name = reader.Value;
                                        break;
                                    case "description":
                                        item.description = reader.Value;
                                        break;
                                    case "file":
                                        item.fileDir = reader.Value;
                                        break;
                                    case "base": //base position declared
                                        string val = reader.Value;
                                        string[] split = val.Split(',');
                                        item.basePosition = new Vector3(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2]));
                                        break;
                                }
                            }
                            //if we get this point, it's mean there is no more attrs to read
                            if (item != null)
                            {
                                items.Add(item);
                            }
                        }
                        break;
                }
            }
            reader.Close();
            loaded = true;
        }
        return loaded;
    }
开发者ID:edumntg,项目名称:jump-dodge,代码行数:52,代码来源:Items.cs

示例14: LoadAndValidateXml

    public static XmlDocument LoadAndValidateXml(string xmlFilename, TextAsset schemaFile, ValidationEventHandler validationEventHandler)
    {
        XmlTextReader textReader = null;
        XmlReader validatingReader = null;

        MemoryStream fs = null;
        try
        {
            textReader = new XmlTextReader(xmlFilename);
            XmlReaderSettings readerSettings = new XmlReaderSettings();
            readerSettings.ValidationType = ValidationType.Schema;
            readerSettings.ValidationEventHandler += validationEventHandler;

            fs = new MemoryStream(Encoding.ASCII.GetBytes(schemaFile.text));
            XmlSchema schema = XmlSchema.Read(fs, validationEventHandler);
            readerSettings.Schemas.Add(schema);

            validatingReader = XmlReader.Create(textReader, readerSettings); //new XmlValidatingReader(textReader);

            XmlDocument result = new XmlDocument();
            result.Load(validatingReader);

            Debug.Log("XML validation finished for " + xmlFilename + "!");

            fs.Close();
            validatingReader.Close();
            textReader.Close();

            return result;
        }
        catch (FileNotFoundException e)
        {
            Debug.LogWarning("Could not find file: " + e.FileName);
            if(fs != null) fs.Close();
            if(validatingReader != null) validatingReader.Close();
            if(textReader != null) textReader.Close();
            return null;
        }
    }
开发者ID:Zerphed,项目名称:miscellaneous,代码行数:39,代码来源:XMLUtil.cs

示例15: Load

    /// <summary>
    /// Create an instance of an object from file.
    /// </summary>
    /// <param name="path">Path to the XML file</param>
    /// <param name="type">Type of object to create</param>
    /// <returns></returns>
    public static object Load( string path, Type type )
    {
        object thing = null;

        Debug.Log("Loading (" + type.Name + "): " + path);

        XmlTextReader reader = new XmlTextReader( path );
        XmlSerializer serializer = new  XmlSerializer( type, AdditionalTypes.ToArray() );
        thing = serializer.Deserialize( reader );
        reader.Close();

        return( thing );
    }
开发者ID:ChristopherConnock,项目名称:Unity-Design-Review-System,代码行数:19,代码来源:XmlIO.cs


注:本文中的XmlTextReader.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。