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


C# XmlDocument.Load方法代码示例

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


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

示例1: Main

    static void Main(string[] args)
    {
        if (args.Length < 2) {
            Console.WriteLine("Usage: BenchSgmlReader.exe filename iterations");
            return;
        }

        var streamReader = new StreamReader(args[0]);
        string text = streamReader.ReadToEnd();
        streamReader.Close();

        int n = int.Parse(args[1]);

        var start = DateTime.Now;
        for (int i = 0; i < n; i++) {
            SgmlReader sgmlReader = new SgmlReader();
            sgmlReader.DocType = "HTML";
            sgmlReader.WhitespaceHandling = WhitespaceHandling.All;
            //sgmlReader.CaseFolding = Sgml.CaseFolding.ToLower;
            sgmlReader.InputStream = new StringReader(text);

            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.XmlResolver = null;
            doc.Load(sgmlReader);
        }
        var stop = DateTime.Now;

        var duration = stop - start;
        Console.WriteLine("{0} s", (duration.TotalMilliseconds / 1000.0).ToString(CultureInfo.InvariantCulture));
    }
开发者ID:FrameworkBy,项目名称:html-parsers-benchmark,代码行数:31,代码来源:BenchSgmlReader.cs

示例2: LoadConfiguration

    public void LoadConfiguration(string Section, string Column)
    {
        _PatternArrayList = new ArrayList();
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.PreserveWhitespace = true;
        Assembly CurrentlyExecutingAssembly = Assembly.GetExecutingAssembly();
        FileInfo CurrentlyExecutingAssemblyFileInfo = new FileInfo(CurrentlyExecutingAssembly.Location);
        string ConfigFilePath = CurrentlyExecutingAssemblyFileInfo.DirectoryName;
        try
        {
            xmlDoc.Load(ConfigFilePath + @"\" + ConfigFileName);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            //  Environment.Exit(1);
            Console.WriteLine("Loading embedded resource");
            // While Loading - note : embedded resource Logical Name is overriden at the project level.
            xmlDoc.Load(CurrentlyExecutingAssembly.GetManifestResourceStream(ConfigFileName));
        }
        // see http://forums.asp.net/p/1226183/2209639.aspx
        if (DEBUG)
            Console.WriteLine("Loading: Section \"{0}\" Column \"{1}\"", Section, Column);

        XmlNodeList nodes = xmlDoc.SelectNodes(Section);
        foreach (XmlNode node in nodes)
        {
            XmlNode DialogTextNode = node.SelectSingleNode(Column);
            string sInnerText = DialogTextNode.InnerText;
            if (!String.IsNullOrEmpty(sInnerText))
            {
                _PatternArrayList.Add(sInnerText);
                if (DEBUG)
                    Console.WriteLine("Found \"{0}\"", sInnerText);
            }
        }
        if (0 == _PatternArrayList.Count)
        {
            if (Debug)
                Console.WriteLine("Invalid Configuration:\nReview Section \"{0}\" Column \"{1}\"", Section, Column);
            MessageBox.Show(
                String.Format("Invalid Configuration file:\nReview \"{0}/{1}\"", Section, Column),
                CurrentlyExecutingAssembly.GetName().ToString(),
                MessageBoxButtons.OK,
                System.Windows.Forms.MessageBoxIcon.Exclamation);
            Environment.Exit(1);
        }
        try
        {
            sDetectorExpression = String.Join("|", (string[])_PatternArrayList.ToArray(typeof(string)));
        }
        catch (Exception e)
        {
            Console.WriteLine("Internal error processing Configuration");
            System.Diagnostics.Debug.Assert(e != null);
            Environment.Exit(1);
        }
        if (DEBUG)
            Console.WriteLine(sDetectorExpression);
    }
开发者ID:testpulse,项目名称:powershell_selenium,代码行数:60,代码来源:configuration.cs

示例3: LoadFromXML

    void LoadFromXML()
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load("./Assets/XML/BullyStats.xml");

        XmlNode root = xmlDoc.FirstChild;

        foreach (XmlNode node in root.ChildNodes)
        {
            m_DetectionDist = 5;
            //Find the node with a matching name as GameObject
            if (node.Name == this.name)
            {
                m_HP = float.Parse(node.Attributes["HP"].Value); //Load the HP value from the XML file
                m_Attack1Damage = float.Parse(node.Attributes["PunchDamage"].Value); //Load the punch damage value from the XML file
                m_Attack2Damage = float.Parse(node.Attributes["KickDamage"].Value); //Load the kick damage value from the XML file
                m_UniqueDamage = float.Parse(node.Attributes["UniqueDamage"].Value); //Load the unique damage value from the XML file
                m_Attack1RestTime = float.Parse(node.Attributes["PunchRest"].Value); //Load the punch rest time from the XML file
                m_Attack2RestTime = float.Parse(node.Attributes["KickRest"].Value); //Load the kick rest time from the XML file
                m_UniqueRestTime = float.Parse(node.Attributes["UniqueRest"].Value); //Load the unique attack rest time from the XML file
                m_Attack1Odds = int.Parse(node.Attributes["PunchOdds"].Value); //Load the punch odds from the XML file
                m_Attack2Odds = int.Parse(node.Attributes["KickOdds"].Value); //Load the kick odds from the XML file
                m_AttackUniqueOdds = int.Parse(node.Attributes["UniqueOdds"].Value); //Load the unique attack odds from the XML file
                m_AttackResetTime = float.Parse(node.Attributes["AttackReset"].Value); //Load the attack reset time from the XML file
                m_VelocityX = int.Parse(node.Attributes["Velocity"].Value); //Load the velocity from the XML file
                m_AttackDist = int.Parse(node.Attributes["AttackDist"].Value);
                //m_ChangeTrackTimer = int.Parse(node.Attributes["ChangeTrackDelay"].Value);
            }
        }
    }
开发者ID:Adlez,项目名称:Wolf_Puncher_Repo,代码行数:30,代码来源:EnemyScript.cs

示例4: 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

示例5: loadActiveTransportProprietiesFromFile

    /*!
    \brief Load all the proprieties from a file
    \param The path of the file
    \return The list of ActiveTranportProprieties. If the list is empty this function return null
       */
    public LinkedList<ActiveTransportProprieties> loadActiveTransportProprietiesFromFile(string filePath)
    {
        LinkedList<ActiveTransportProprieties>      propsList = new LinkedList<ActiveTransportProprieties>();
        ActiveTransportProprieties                  prop;

        MemoryStream ms = Tools.getEncodedFileContent(filePath);
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(ms);

        XmlNodeList ATsLists = xmlDoc.GetElementsByTagName("activeTransports");
        foreach (XmlNode ATsNodes in ATsLists)
          {
        foreach (XmlNode ATNode in ATsNodes)
          {
            if (ATNode.Name == "ATProp")
              {
                prop = loadActiveTransportProprieties(ATNode);
                propsList.AddLast(prop);
              }
          }
          }

        if (propsList.Count == 0)
          return null;
        return propsList;
    }
开发者ID:CyberCRI,项目名称:DsynBio,代码行数:31,代码来源:ActiveTransportLoader.cs

示例6: Button1_Click

 protected void Button1_Click(object sender, EventArgs e)
 {
     XmlDocument document = new XmlDocument();
     string serverPath = Public.GetServerPath();
     document.Load(serverPath + @"\\bin\\DataMessage.xml");
     foreach (XmlNode node in document.SelectNodes("/DataMessage/DataTableItem"))
     {
         XmlElement element = (XmlElement)node;
         if (element.GetAttribute("TableName") == this.txtTableNameVal.Value.Trim())
         {
             element.SetAttribute("TableName", this.txtTableName.Text.Trim());
             element.SetAttribute("Text", this.txtTableChina.Text.Trim());
             foreach (XmlNode node2 in element.ChildNodes)
             {
                 XmlElement element2 = (XmlElement)node2;
                 if (element2.GetAttribute("ColumnName") == this.txtColNameVal.Value.Trim())
                 {
                     element2.InnerText = this.txtColChina.Text.Trim();
                     element2.SetAttribute("ColumnName", this.txtColName.Text.Trim());
                     element2.SetAttribute("ColumnType", this.ddlDataType.SelectedValue);
                     break;
                 }
             }
             break;
         }
     }
     document.Save(serverPath + @"\\bin\\DataMessage.xml");
     Public.Show("修改成功!");
     this.ClearForm();
     this.BindTableMess();
     this.ddlTableName_SelectedIndexChanged(sender, e);
 }
开发者ID:SoMeTech,项目名称:SoMeRegulatory,代码行数:32,代码来源:XmlEdit.aspx.cs

示例7: DeleteAttribute

    /// <summary>
    /// 删除XmlNode属性
    /// 使用示列:
    /// XmlHelper.DeleteAttribute(path, nodeName, "");
    /// XmlHelper.DeleteAttribute(path, nodeName, attributeName,attributeValue);
    /// </summary>
    /// <param name="path">文件路径</param>
    /// <param name="nodeName">节点名称</param>
    /// <param name="attributeName">属性名称</param>
    /// <returns>void</returns>
    public static void DeleteAttribute(string path, string nodeName, string attributeName)
    {
        if (attributeName.Equals(""))
        {
            return;
        }

        try
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(path);

            XmlElement element = doc.SelectSingleNode(nodeName) as XmlElement;
            if (element == null)
            {
                throw new Exception("节点元素不存在!");
            }
            else
            {
                element.RemoveAttribute(attributeName);
                doc.Save(path);
            }
        }
        catch
        { }
    }
开发者ID:hj-nicholas,项目名称:BaseFrame,代码行数:36,代码来源:XmlHelper.cs

示例8: WriteToXml

    public static void WriteToXml(string namePlayer)
    {
        string filepath = Application.dataPath + @"/Data/hightScores.xml";
        XmlDocument xmlDoc = new XmlDocument();

        if (File.Exists(filepath))
        {
            xmlDoc.Load(filepath);

            XmlElement elmRoot = xmlDoc.DocumentElement;

           // elmRoot.RemoveAll(); // remove all inside the transforms node.

            XmlElement scoresHelper = xmlDoc.CreateElement("allScores"); // create the rotation node.

            XmlElement name = xmlDoc.CreateElement("name"); // create the x node.
            name.InnerText = namePlayer; // apply to the node text the values of the variable.

            XmlElement score = xmlDoc.CreateElement("score"); // create the x node.
            score.InnerText = "" + Game.points; // apply to the node text the values of the variable.

            scoresHelper.AppendChild(name); // make the rotation node the parent.
            scoresHelper.AppendChild(score); // make the rotation node the parent.

            elmRoot.AppendChild(scoresHelper); // make the transform node the parent.

            xmlDoc.Save(filepath); // save file.
        }
    }
开发者ID:olon,项目名称:Snake3D,代码行数:29,代码来源:HightScoreHelper.cs

示例9: Main

	public static void Main (string [] args)
	{
		bool outAll = false;
		bool details = false;
		bool stopOnError = false;
		string filter = null;
		foreach (string arg in args) {
			switch (arg) {
			case "--outall":
				outAll = true; break;
			case "--details":
				details = true; break;
			case "--stoponerror":
				stopOnError = true; break;
			default:
				filter = arg; break;
			}
		}

		try {
			XmlDocument doc = new XmlDocument ();
			doc.Load ("test/RNCTest.xml");
			int success = 0;
			int failure = 0;
			foreach (XmlElement el in doc.SelectNodes ("/RNCTestCases/TestCase")) {
				string id = el.GetAttribute ("id");
				if (filter != null && id.IndexOf (filter) < 0)
					continue;
				if (outAll)
					Console.WriteLine ("testing " + id);
				bool isValid = el.GetAttribute ("legal") == "true";
				RncParser p = new RncParser (new NameTable ());
				try {
					string s = new StreamReader ("test" + Path.DirectorySeparatorChar + el.GetAttribute ("path")).ReadToEnd ();
					p.Parse (new StringReader (s));
					if (isValid) {
						success++;
//						Console.Error.WriteLine ("valid " + id);
					} else {
						failure++;
						Console.Error.WriteLine ("INCORRECTLY VALID   " + id);
					}
				} catch (Exception ex) {
					if (isValid) {
						if (stopOnError)
							throw;
						failure++;
						Console.Error.WriteLine ("INCORRECTLY INVALID " + id + " --> " + (details ? ex.ToString () : ex.Message));
					} else {
						success++;
//						Console.Error.WriteLine ("invalid " + id);
					}
				}
			}
			Console.Error.WriteLine ("Total success: " + success);
			Console.Error.WriteLine ("Total failure: " + failure);
		} catch (Exception ex) {
			Console.Error.WriteLine ("Unexpected Exception: " + ex);
		}
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:60,代码来源:anglia-test-runner.cs

示例10: Main

    static void Main()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load("../../library.xml");
        Console.WriteLine("Loaded XML document:");
        Console.WriteLine(doc.OuterXml);
        Console.WriteLine();

        XmlNode rootNode = doc.DocumentElement;
        Console.WriteLine("Root node: {0}", rootNode.Name);

        foreach (XmlAttribute atr in rootNode.Attributes)
        {
            Console.WriteLine("Attribute: {0}={1}", atr.Name, atr.Value);
        }
        Console.WriteLine();

        foreach (XmlNode node in rootNode.ChildNodes)
        {
            Console.WriteLine("Book title = {0}", node["title"].InnerText);
            Console.WriteLine("Book author = {0}", node["author"].InnerText);
            Console.WriteLine("Book isbn = {0}", node["isbn"].InnerText);
            Console.WriteLine();
        }
    }
开发者ID:syssboxx,项目名称:Database-Applications,代码行数:25,代码来源:DOMParser.cs

示例11: Main

    /* 11. Write a program, which extract from the file catalog.xml the prices for all albums,
     * published 5 years ago or earlier. Use XPath query.*/

    static void Main(string[] args)
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load("../../catalog.xml");
        string xPathQuery = "/catalog/album";

        XmlNodeList albums = xmlDoc.SelectNodes(xPathQuery);

        var prices = new List<decimal>();

        foreach (XmlNode album in albums)
        {
            var year = int.Parse(album.SelectSingleNode("year").InnerText);
            var publishDate = new DateTime(year, 1, 1);
            if (DateTime.Now.Year - publishDate.Year > 5)
            {
                prices.Add(decimal.Parse(album.SelectSingleNode("price").InnerText));
            }
        }

        foreach (var price in prices)
        {
            Console.WriteLine(price);
        }
    }
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:28,代码来源:Program.cs

示例12: Load

    public static List<LeftMenu> Load()
    {
        XmlDocument xml = new XmlDocument();
            xml.Load(HttpContext.Current.Request.PhysicalApplicationPath + "/App_Data/Menu.config");
            List<LeftMenu> menus = new List<LeftMenu>();
            XmlNodeList menuNodes = xml.SelectNodes("Menus/Menu");
            foreach (XmlNode menuNode in menuNodes)
            {
                LeftMenu menu = new LeftMenu();
                menu.Code = menuNode.Attributes["code"].Value;
                menu.Title = menuNode.Attributes["title"].Value;
                menu.Href = menuNode.Attributes["href"].Value;
                menu.Img = menuNode.Attributes["img"].Value;

                foreach (XmlNode linkNode in menuNode.ChildNodes)
                {
                    MenuLink link = new MenuLink();
                    link.Code = linkNode.Attributes["code"].Value;
                    link.Title = linkNode.Attributes["title"].Value;
                    link.Href = linkNode.Attributes["href"].Value;
                    menu.Links.Add(link);
                }
                menus.Add(menu);
            }
            return menus;
    }
开发者ID:priceLiu,项目名称:CMS,代码行数:26,代码来源:LeftMenu.cs

示例13: GetAllSongs

    private void GetAllSongs()
    {
        string returnJSON = "[";

        XmlDocument doc = new XmlDocument();
        doc.Load(Server.MapPath("../Xml/Data.xml"));

        XmlNodeList nodeList = doc.GetElementsByTagName("song");
        int counter = 0;
        foreach (XmlNode song in nodeList)
        {
            string id = song.ChildNodes[0].FirstChild.Value,
                    title = song.ChildNodes[1].FirstChild.Value;

            returnJSON += "{ \"id\" : \"" + id + "\", \"title\" : \"" + title + "\" }";

            counter++;
            if (counter < nodeList.Count)
            {
                returnJSON += ",";
            }
        }

        returnJSON += "]";

        Response.Write(returnJSON);
    }
开发者ID:TryingToImprove,项目名称:MusicDB-OldFunProject,代码行数:27,代码来源:Default.aspx.cs

示例14: Module_Action_Delete

 private string Module_Action_Delete()
 {
     string tmpstr = "";
     string trootstr = cls.getSafeString(encode.base64.decodeBase64(request.querystring("root")));
     string tvaluestr = cls.getSafeString(encode.base64.decodeBase64(request.querystring("value")));
     if (com.fileExists(Server.MapPath(trootstr)))
     {
       try
       {
     string tnode, tfield, tbase;
     XmlDocument tXMLDom = new XmlDocument();
     tXMLDom.Load(Server.MapPath(trootstr));
     XmlNode tXmlNode = tXMLDom.SelectSingleNode("/xml/configure");
     tnode = tXmlNode.ChildNodes.Item(0).InnerText;
     tfield = tXmlNode.ChildNodes.Item(1).InnerText;
     tbase = tXmlNode.ChildNodes.Item(2).InnerText;
     XmlNode tXmlNodeDel = tXMLDom.SelectSingleNode("/xml/" + tbase + "/" + tnode + "[" + cls.getLRStr(tfield, ",", "left") + "='" + tvaluestr + "']");
     if (tXmlNodeDel != null)
     {
       tXmlNodeDel.ParentNode.RemoveChild(tXmlNodeDel);
       tXMLDom.Save(Server.MapPath(trootstr));
     }
     tmpstr = jt.itake("global.lng_common.delete-succeed", "lng");
       }
       catch
       {
     tmpstr = jt.itake("global.lng_common.delete-failed", "lng");
       }
     }
     else tmpstr = jt.itake("global.lng_common.delete-failed", "lng");
     tmpstr = config.ajaxPreContent + tmpstr;
     return tmpstr;
 }
开发者ID:dengfan,项目名称:jtbc-plus,代码行数:33,代码来源:manage-interface.cs

示例15: OpenAppXMLFile

    public XmlDocument OpenAppXMLFile()
    {
        string App_Path = @ConfigurationManager.AppSettings["Data_Path"].ToString();
        App_Path = App_Path + "Items.xml";

        if (File.Exists(@App_Path))
        {
            try
            {
                xmldoc = new XmlDocument();
                xmldoc.Load(@App_Path);
            }
            catch (Exception ex)
            {
                ///  Do not currently understand how to terminate the ThreadStart in the event of a failure
                GlobalClass.ErrorMessage = "Error in AppThreads(OpenAppFile): " + ex.Message;

            }

        }
        else
        {
            xmldoc = new XmlDocument();
            XmlNode iheader = xmldoc.CreateXmlDeclaration("1.0", "UTF-8", null);
            xmldoc.AppendChild(iheader);
            XmlElement root = xmldoc.CreateElement("dataroot");
            xmldoc.InsertAfter(root, iheader);
            xmldoc.Save(@App_Path);

        }

         return  xmldoc;
    }
开发者ID:emcgurty,项目名称:ASP_NET_with_XML_List,代码行数:33,代码来源:GetXMLdoc.cs


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