• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# XmlDocument类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: GetAttributesOnTextNode

        public static void GetAttributesOnTextNode()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a>text node</a>");

            Assert.Null(xmlDocument.DocumentElement.FirstChild.Attributes);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:AttributesTests.cs


示例2: Main

    static void Main()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(@"..\..\..\catalogue.xml");
        XmlNode rootNode = doc.DocumentElement;

        for (int i = 0; i < rootNode.ChildNodes.Count; i++)
        {
            XmlNode node = rootNode.ChildNodes[i];

            foreach (XmlNode albumPrice in node.ChildNodes)
            {
                // if the node is the price node
                if (albumPrice.Name == "price")
                {
                    // take the price
                    double price = double.Parse(albumPrice.InnerText);
                    if (price > 20.00)
                    {
                        rootNode.RemoveChild(node); // remove the node
                        i--; // decrementing i so that we won't miss a node
                    }
                }
            }
        }

        doc.Save(@"..\..\..\catalogueUnderTwentyPrice.xml");
    }
开发者ID:YavorIT,项目名称:DatabaseOnlineCourseTelerikHW,代码行数:28,代码来源:DOMDelete.cs


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


示例4: DocumentNodeTypeTest

        public static void DocumentNodeTypeTest()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a />");

            Assert.Equal(XmlNodeType.Document, xmlDocument.NodeType);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:NodeTypeTests.cs


示例5: GetUpdateList

    private void GetUpdateList(string updateKey)
    {
        WebClient client = new WebClient();
        client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

        string response;

        try
        {
            response = client.UploadString("http://infinity-code.com/products_update/checkupdates.php",
            "k=" + WWW.EscapeURL(updateKey) + "&v=" + OnlineMaps.version + "&c=" + (int)channel);
        }
        catch
        {
            return;
        }
        
        XmlDocument document = new XmlDocument();
        document.LoadXml(response);

        XmlNode firstChild = document.FirstChild;
        updates = new List<OnlineMapsUpdateItem>();

        foreach (XmlNode node in firstChild.ChildNodes) updates.Add(new OnlineMapsUpdateItem(node));
    }
开发者ID:juliancruz87,项目名称:transpp,代码行数:25,代码来源:OnlineMapsUpdater.cs


示例6: SetCountriesName

    public static void SetCountriesName(string language)
    {
        Debug.Log("countries....." +  language);
        TextAsset textAsset = (TextAsset) Resources.Load("countries");
        var xml = new XmlDocument ();
        xml.LoadXml (textAsset.text);

        Countries = new Hashtable();
        AppCountries = new SortedList();

        try{
            var element = xml.DocumentElement[language];
            if (element != null) {
                var elemEnum = element.GetEnumerator();
                while (elemEnum.MoveNext()) {
                    var xmlItem = (XmlElement)elemEnum.Current;
                    Countries.Add(xmlItem.GetAttribute("name"), xmlItem.InnerText);
                    AppCountries.Add(xmlItem.GetAttribute("name"), xmlItem.InnerText);
                }
            } else {
                Debug.LogError("The specified language does not exist: " + language);
            }

        }
        catch (Exception ex)
        {
            Debug.Log("Language:SetCountryName()" + ex.ToString());
        }
    }
开发者ID:jmoraltu,项目名称:KatoizApp,代码行数:29,代码来源:Language.cs


示例7: GetData

    public void GetData()
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(LevelStats.text);

        StartCoroutine(LoadLevelStats(xmlDoc));
    }
开发者ID:SeniorTeam,项目名称:MonkeyHead,代码行数:7,代码来源:LevelManager.cs


示例8: TestOASIS

	public void TestOASIS ()
	{
		XmlDocument doc = new XmlDocument ();
		doc.NodeInserting += new XmlNodeChangedEventHandler (OnInserting);
		doc.NodeInserted += new XmlNodeChangedEventHandler (OnInserted);
		doc.NodeChanging += new XmlNodeChangedEventHandler (OnChanging);
		doc.NodeChanged += new XmlNodeChangedEventHandler (OnChanged);
		doc.NodeRemoving += new XmlNodeChangedEventHandler (OnRemoving);
		doc.NodeRemoved += new XmlNodeChangedEventHandler (OnRemoved);

		foreach (FileInfo fi in
			new DirectoryInfo (@"xml-test-suite/xmlconf/oasis").GetFiles ("*.xml")) {
			try {
				if (fi.Name.IndexOf ("fail") >= 0)
					continue;

				Console.WriteLine ("#### File: " + fi.Name);

				XmlTextReader xtr = new XmlTextReader (fi.FullName);
				xtr.Namespaces = false;
				xtr.Normalization = true;
				doc.RemoveAll ();
				doc.Load (xtr);

			} catch (XmlException ex) {
				if (fi.Name.IndexOf ("pass") >= 0)
					Console.WriteLine ("Incorrectly invalid: " + fi.FullName + "\n" + ex.Message);
			}
		}
	}
开发者ID:nobled,项目名称:mono,代码行数:30,代码来源:eventdump.cs


示例9: Adjust

    public void Adjust(string fileName)
    {
        try
        {
            string path = Path.GetDirectoryName(Application.dataPath+"..");
            if (File.Exists(path+"/"+fileName))
            {
                TextReader tx = new StreamReader(path+"/"+fileName);
                if (doc == null)
                    doc = new XmlDocument();
                doc.Load(tx);
                tx.Close();
                if (doc!=null && doc.DocumentElement!=null)
                {
                    string xmlns = doc.DocumentElement.Attributes["xmlns"].Value;
                    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                    nsmgr.AddNamespace("N",xmlns);

                    SetNode("TargetFrameworkVersion","v4.0", nsmgr);
                    // SetNode("DefineConstants","TRACE;UNITY_3_5_6;UNITY_3_5;UNITY_EDITOR;ENABLE_PROFILER;UNITY_STANDALONE_WIN;ENABLE_GENERICS;ENABLE_DUCK_TYPING;ENABLE_TERRAIN;ENABLE_MOVIES;ENABLE_WEBCAM;ENABLE_MICROPHONE;ENABLE_NETWORK;ENABLE_CLOTH;ENABLE_WWW;ENABLE_SUBSTANCE", nsmgr);

                    TextWriter txs = new StreamWriter(path+"/"+fileName);
                    doc.Save(txs);
                    txs.Close();
                }
            }
        }
        catch(System.Exception)
        {
        }
    }
开发者ID:borderpointer,项目名称:zhoras-adventure,代码行数:31,代码来源:OTAssetPostProcessor.cs


示例10: Main

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

        XmlNodeList ArtistsList = xmlDoc.SelectNodes(xPathQuery);
        Dictionary<string, int> artistsAndAlbumsCount = new Dictionary<string, int>();

        foreach (XmlNode ArtistNode in ArtistsList)
        {
            string authorName = ArtistNode.SelectSingleNode("artist").InnerText;
            if (artistsAndAlbumsCount.ContainsKey(authorName))
            {
                artistsAndAlbumsCount[authorName]++;
            }
            else
            {
                artistsAndAlbumsCount.Add(authorName, 1);
            }
        }

        foreach (var artist in artistsAndAlbumsCount)
        {
            Console.WriteLine("Artist: {0}", artist.Key);
            Console.WriteLine("Albums count: {0}", artist.Value);
            Console.WriteLine();
        }
    }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:29,代码来源:ExtractDataUsingXPath.cs


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


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


示例13: GetAttributesOnDocumentFragment

        public static void GetAttributesOnDocumentFragment()
        {
            var xmlDocument = new XmlDocument();
            var documentFragment = xmlDocument.CreateDocumentFragment();

            Assert.Null(documentFragment.Attributes);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:AttributesTests.cs


示例14: GetAttributesOnCDataNode

        public static void GetAttributesOnCDataNode()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a><![CDATA[test data]]></a>");

            Assert.Null(xmlDocument.DocumentElement.FirstChild.Attributes);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:AttributesTests.cs


示例15: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        //Load document
        string booksFile = Server.MapPath("books.xml");

        XmlDocument document = new XmlDocument();
        document.Load(booksFile);
        XPathNavigator nav = document.CreateNavigator();

        //Add a namespace prefix that can be used in the XPath expression
        XmlNamespaceManager namespaceMgr = new XmlNamespaceManager(nav.NameTable);
        namespaceMgr.AddNamespace("b", "http://example.books.com");

        //All books whose price is not greater than 10.00
        foreach (XPathNavigator node in
            nav.Select("//b:book[not(b:price[. > 10.00])]/b:price",
            namespaceMgr))
        {
            Decimal price = (decimal)node.ValueAs(typeof(decimal));
            node.SetTypedValue(price * 1.2M);
            Response.Write(String.Format("Price raised from {0} to {1}<BR/>",
                price,
                node.ValueAs(typeof(decimal))));
        }
    }
开发者ID:kacecode,项目名称:SchoolWork,代码行数:25,代码来源:Default.aspx.cs


示例16: initialiseSpellButtons

 public void initialiseSpellButtons(XmlDocument xmlDoc)
 {
     XmlNodeList spellList = xmlDoc.GetElementsByTagName("spells")[0].ChildNodes;
     for(int i = 0; i < spellButtons.Length; i++) {
         CmdSpawn(i, spellList[i].LastChild.InnerText);
     }
 }
开发者ID:CalvoR,项目名称:2016_3A_Unity_Calvo_GodVSMan,代码行数:7,代码来源:gvmGodSceneManager.cs


示例17: MakeList

    public void MakeList()
    {
        XmlDocument xmlDoc = new XmlDocument(); // xmlDoc is the new xml document.
        xmlDoc.LoadXml(ELEData.text); // load the file.
        XmlNodeList EleList = xmlDoc.GetElementsByTagName("storeElement"); // array of the level nodes.
        GameObject eleGO;
        StoreElement strElmnt;
        int i = 0;
        foreach (XmlNode eleInfo in EleList)
        {
            int pfI = int.Parse(eleInfo.Attributes["storeType"].Value);
            eleGO = (GameObject)Instantiate(ELEPrefab[pfI]);
            if(pfI==0){
                Text txtEl = eleGO.GetComponent<Text>();
                txtEl.text = LanguageManager.current.getText(eleInfo.Attributes["name"].Value);
            }else if(pfI==1){
                strElmnt = eleGO.GetComponent<StoreElement>();
                int toolIndex = int.Parse(eleInfo.Attributes["imageIndex"].Value);
                strElmnt.init(
                    eleInfo.Attributes["id"].Value,
                    i,
                    LanguageManager.current.getText(eleInfo.Attributes["name"].Value),
                    LanguageManager.current.getSentance(eleInfo.Attributes["desc"].Value,"20"),
                    (ToolType)toolIndex,
                    ElEImages[toolIndex],
                    (eleInfo.Attributes["upgrades"] != null)
                );
                elmentList.Add(strElmnt);
            }

            eleGO.transform.SetParent(gridGroup.transform);
            eleGO.transform.localScale = Vector3.one;

        }
    }
开发者ID:achievegame,项目名称:MineDrill,代码行数:35,代码来源:StoreManager.cs


示例18: dump

 /*
 ****************************************************************************
 * dump()
 ****************************************************************************
 */
 /**
 * Returns obj as a formatted XML string.
 * @param sTab - The characters to prepend before each new line
 */
 public string dump()
 {
     XmlDocument doc = new XmlDocument();
     XmlElement elm = this.toDOM(doc);
     doc.AppendChild(elm);
     return DOMUtils.ToString(doc);
 }
开发者ID:AArnott,项目名称:dotnetxri,代码行数:16,代码来源:AttributeStatement.cs


示例19: DL_SubjectArealist_ItemDatabound

    protected void DL_SubjectArealist_ItemDatabound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            ListViewDataItem ditem = (ListViewDataItem)e.Item;
            //data reader
            System.Data.DataRowView item = (System.Data.DataRowView)ditem.DataItem;
            Literal myfavicons = (Literal)ditem.FindControl("myfavicons");
            HyperLink SubjectAreaTitle = (HyperLink)ditem.FindControl("SubjectAreaTitle");
            Literal Description = (Literal)ditem.FindControl("Description");

            XmlDocument XMLDoc = new XmlDocument();
            XMLDoc.LoadXml(item["content_html"].ToString());

            string ShortDescription = commonfunctions.getFieldValue(XMLDoc, "ShortDescription", "/SubjectAreas");
            string Name = commonfunctions.getFieldValue(XMLDoc, "Name", "/SubjectAreas");

            long saId = long.Parse(item["content_id"].ToString());
            Description.Text = ShortDescription;
            myfavicons.Text = commonfunctions.getMyFavIcons(saId.ToString(), "2", Title, "0");
            SubjectAreaTitle.Text = Name;
            SubjectAreaTitle.NavigateUrl = commonfunctions.getQuickLink(saId); ;

        }
    }
开发者ID:femiosinowo,项目名称:sssadl,代码行数:25,代码来源:subjectarea.aspx.cs


示例20: CreateCdata

        public static void CreateCdata()
        {
            var xmlDocument = new XmlDocument();
            var cdataNode = (XmlCharacterData)xmlDocument.CreateCDataSection("abcde");

            Assert.Equal(5, cdataNode.Length);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:7,代码来源:LengthTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# XmlElement类代码示例发布时间:2022-05-24
下一篇:
C# XmlDeserializer类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap