當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlDocument.LoadXml方法代碼示例

本文整理匯總了C#中System.Xml.XmlDocument.LoadXml方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.LoadXml方法的具體用法?C# XmlDocument.LoadXml怎麽用?C# XmlDocument.LoadXml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.LoadXml方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: LoadXml

        /// <summary>
        /// loads a xml from the web server
        /// </summary>
        /// <param name="_url">URL of the XML file</param>
        /// <returns>A XmlDocument object of the XML file</returns>
        public static XmlDocument LoadXml(string _url)
        {
            var xmlDoc = new XmlDocument();
            
            try
            {
                while (Helper.pingForum("forum.mods.de", 10000) == false)
                {
                    Console.WriteLine("Can't reach forum.mods.de right now, try again in 15 seconds...");
                    System.Threading.Thread.Sleep(15000);
                }

                xmlDoc.Load(_url);
            }
            catch (XmlException)
            {
                while (Helper.pingForum("forum.mods.de", 100000) == false)
                {
                    Console.WriteLine("Can't reach forum.mods.de right now, try again in 15 seconds...");
                    System.Threading.Thread.Sleep(15000);
                }

                WebClient client = new WebClient(); ;
                Stream stream = client.OpenRead(_url);
                StreamReader reader = new StreamReader(stream);
                string content = reader.ReadToEnd();

                content = RemoveTroublesomeCharacters(content);
                xmlDoc.LoadXml(content);
            }

            return xmlDoc;
        }
開發者ID:tpf89,項目名稱:mods.de-XML-Parser-for-Windows,代碼行數:38,代碼來源:Helper.cs

示例2: saveXml

 private void saveXml()
 {
     string error = String.Empty;
     XmlDocument modifiedXml = new XmlDocument();
     modifiedXml.LoadXml(txtXml.Text);
     pageNode.SetPersonalizationFromXml(HttpContext.Current, modifiedXml, out error);
 }
開發者ID:maxpavlov,項目名稱:FlexNet,代碼行數:7,代碼來源:PageAdminPortlet.cs

示例3: DlgTips_Load

        private void DlgTips_Load(object sender, EventArgs e)
        {   
            try
            {
                string strxml = "";
                using (StreamReader streamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Johnny.Kaixin.WinUI.Resources.Versions.config")))
                {
                    strxml = streamReader.ReadToEnd();
                }

                XmlDocument objXmlDoc = new XmlDocument();
                objXmlDoc.LoadXml(strxml);

                if (objXmlDoc == null)
                    return;

                DataView dv = GetData(objXmlDoc, "ZrAssistant/Versions");

                for (int ix = 0; ix < dv.Table.Rows.Count; ix++)
                {
                    _versionList.Add(dv.Table.Rows[ix][0].ToString(), dv.Table.Rows[ix][1].ToString());
                    cmbVersion.Items.Add(dv.Table.Rows[ix][0].ToString());
                }

                chkNeverDisplay.Checked = Properties.Settings.Default.NeverDisplay;
                cmbVersion.SelectedIndex = 0;
                SetTextValue();
                btnOk.Select();
            }
            catch (Exception ex)
            {
                Program.ShowMessageBox("DlgTips", ex);
            }
        }
開發者ID:jojozhuang,項目名稱:Projects,代碼行數:34,代碼來源:DlgTips.cs

示例4: GeoIP

        public GeoIP()
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://freegeoip.net/xml/");
                request.Proxy = null;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream dataStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream);
                string responseString = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
                response.Close();

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(responseString);

                WANIP = doc.SelectSingleNode("Response//Ip").InnerXml.ToString();
                Country = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//CountryName").InnerXml.ToString())) ? doc.SelectSingleNode("Response//CountryName").InnerXml.ToString() : "Unknown";
                CountryCode = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//CountryCode").InnerXml.ToString())) ? doc.SelectSingleNode("Response//CountryCode").InnerXml.ToString() : "-";
                Region = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//RegionName").InnerXml.ToString())) ? doc.SelectSingleNode("Response//RegionName").InnerXml.ToString() : "Unknown";
                City = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//City").InnerXml.ToString())) ? doc.SelectSingleNode("Response//City").InnerXml.ToString() : "Unknown";
            }
            catch
            {
                WANIP = "-";
                Country = "Unknown";
                CountryCode = "-";
                Region = "Unknown";
                City = "Unknown";
            }
        }
開發者ID:kr-app-a72,項目名稱:Computer-Info,代碼行數:32,代碼來源:GeoIP.cs

示例5: TestCompFilter

    public void TestCompFilter()
    {
      var uut = new CompFilter(ResourceType.VEVENT);
      var xmlDoc = new XmlDocument();

      xmlDoc.LoadXml(AddNamespace(uut.ToXml()));

      Assert.AreEqual(1, xmlDoc.GetElementsByTagName("C:comp-filter").Count);
      var element = xmlDoc.GetElementsByTagName("C:comp-filter")[0];
      Assert.AreEqual(ResourceType.VEVENT.ToString(), element.Attributes["name"].Value);
      Assert.AreEqual(0, element.ChildNodes.Count);

      uut.AddChild(new TimeRangeFilter() { Start = new DateTime(2000, 1, 1, 21, 0, 0) });
      xmlDoc.LoadXml(AddNamespace(uut.ToXml()));
      element = xmlDoc.GetElementsByTagName("C:comp-filter")[0];

      Assert.AreEqual(1, element.ChildNodes.Count);

      try
      {
        uut.AddChild(new TimeRangeFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }

      uut = new CompFilter(ResourceType.VCALENDAR);
      uut.AddChild(new IsNotDefinedFilter());
      try
      {
        uut.AddChild(new CompFilter(ResourceType.VEVENT));
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
    }
開發者ID:flom,項目名稱:caldavclient,代碼行數:34,代碼來源:FilterTest.cs

示例6: LoadLanguages

        /// <summary>
        /// Load language files
        /// </summary>
        public static List<MultiLangEngine> LoadLanguages()
        {
            List<MultiLangEngine> languages = new List<MultiLangEngine>();

            /* Check if language dir exists
             * 1. If it does, scan it
             * 2. If it doesn't, skip it
             */
            string langPath = Environment.CurrentDirectory + @"\lang\";
            if (Directory.Exists(langPath))
            {
                // 1
                languages = MultiLangEngine.ScanDirectory(langPath);
            }

            /* 
             * Load built-in language files
             */
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(Properties.Resources.dwas2_en_US);
                languages.Add(new MultiLangEngine(xmldoc));
                xmldoc.LoadXml(Properties.Resources.dwas2_zh_CN);
                languages.Add(new MultiLangEngine(xmldoc));
            }
            catch (Exception ex)
            {
                // skip
            }

            return languages;
        }
開發者ID:logchan,項目名稱:desktop-wallpaper-auto-switch-2,代碼行數:36,代碼來源:DWAS2LanguageManager.cs

示例7: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            uToolsCore.Authorize();

            string mediaID = HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["mediaID"]);
            XmlDocument resultDocument = new XmlDocument();

            try
            {

                XPathNodeIterator xn = umbraco.library.GetMedia(Convert.ToInt32(mediaID), true);
                xn.MoveNext();

                resultDocument.LoadXml("<uTools>" + xn.Current.OuterXml + "</uTools>");
            }

            catch (Exception e2)
            {
                resultDocument.LoadXml("<uTools><noResults/></uTools>");
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentType = "text/xml";
            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
            resultDocument.Save(HttpContext.Current.Response.Output);
            HttpContext.Current.Response.End();
        }
開發者ID:kgiszewski,項目名稱:uTools,代碼行數:27,代碼來源:mediacachexml.aspx.cs

示例8: Add

		public void Add ()
		{
			XmlSchemaSet ss = new XmlSchemaSet ();
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' />");
			ss.Add (null, new XmlNodeReader (doc)); // null targetNamespace
			ss.Compile ();

			// same document, different targetNamespace
			ss.Add ("ab", new XmlNodeReader (doc));

			// Add(null, xmlReader) -> targetNamespace in the schema
			doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:foo' />");
			ss.Add (null, new XmlNodeReader (doc));

			Assert.AreEqual (3, ss.Count);

			bool chameleon = false;
			bool ab = false;
			bool urnfoo = false;

			foreach (XmlSchema schema in ss.Schemas ()) {
				if (schema.TargetNamespace == null)
					chameleon = true;
				else if (schema.TargetNamespace == "ab")
					ab = true;
				else if (schema.TargetNamespace == "urn:foo")
					urnfoo = true;
			}
			Assert.IsTrue (chameleon, "chameleon schema missing");
			Assert.IsTrue (ab, "target-remapped schema missing");
			Assert.IsTrue (urnfoo, "target specified in the schema ignored");
		}
開發者ID:user277,項目名稱:mono,代碼行數:33,代碼來源:XmlSchemaSetTests.cs

示例9: RssParser

        public RssParser (string url, string xml)
        {
            this.url = url;
            xml = xml.TrimStart ();
            doc = new XmlDocument ();
            try {
                doc.LoadXml (xml);
            } catch (XmlException e) {
                bool have_stripped_control = false;
                StringBuilder sb = new StringBuilder ();

                foreach (char c in xml) {
                    if (Char.IsControl (c) && c != '\n') {
                        have_stripped_control = true;
                    } else {
                        sb.Append (c);
                    }
                }

                bool loaded = false;
                if (have_stripped_control) {
                    try {
                        doc.LoadXml (sb.ToString ());
                        loaded = true;
                    } catch (Exception) {
                    }
                }

                if (!loaded) {
                    Hyena.Log.Exception (e);
                    throw new FormatException ("Invalid XML document.");
                }
            }
            CheckRss ();
        }
開發者ID:petejohanson,項目名稱:banshee,代碼行數:35,代碼來源:RssParser.cs

示例10: execStoredProc

 public XmlDocument execStoredProc(String strProcName, XmlDocument strParameters)
 {
     XmlDocument Result = new XmlDocument();
     SqlConnection sConn = new SqlConnection();
     sConn = getPooledConnection(sConn);
     try
     {
         sConn.Open();
         SqlCommand command = new SqlCommand(strProcName, sConn);
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.Add("@p", SqlDbType.Xml).Value = strParameters.InnerXml;
         SqlParameter result = command.Parameters.Add
                    ("@r", SqlDbType.Xml);
         result.Direction = ParameterDirection.Output;
         command.ExecuteNonQuery();
         Result.LoadXml(result.Value.ToString());
         sConn.Close();
     }
     catch (Exception exp)
     {
         Result.LoadXml(exp.ToString());
         sConn.Close();
     }
     return (Result);
 }
開發者ID:GaugeBosonIT,項目名稱:Schapp,代碼行數:25,代碼來源:Proc.cs

示例11: TimedTextStyles

        public TimedTextStyles(Subtitle subtitle)
        {
            InitializeComponent();

            _subtitle = subtitle;
            _xml = new XmlDocument();
            try
            {
                _xml.LoadXml(subtitle.Header);
                var xnsmgr = new XmlNamespaceManager(_xml.NameTable);
                xnsmgr.AddNamespace("ttml", "http://www.w3.org/ns/ttml");
                if (_xml.DocumentElement.SelectSingleNode("ttml:head", xnsmgr) == null)
                    _xml.LoadXml(new TimedText10().ToText(new Subtitle(), "tt")); // load default xml
            }
            catch
            {
                _xml.LoadXml(new TimedText10().ToText(new Subtitle(), "tt")); // load default xml
            }
            _nsmgr = new XmlNamespaceManager(_xml.NameTable);
            _nsmgr.AddNamespace("ttml", "http://www.w3.org/ns/ttml");
            _xmlHead = _xml.DocumentElement.SelectSingleNode("ttml:head", _nsmgr);

            foreach (FontFamily ff in FontFamily.Families)
                comboBoxFontName.Items.Add(ff.Name.Substring(0, 1).ToLower() + ff.Name.Substring(1));

            InitializeListView();

            _previewTimer.Interval = 200;
            _previewTimer.Tick += RefreshTimerTick;
        }
開發者ID:rragu,項目名稱:subtitleedit,代碼行數:30,代碼來源:TimedTextStyles.cs

示例12: ParsePMIDs

        public List<string> ParsePMIDs(string xml)
        {
            if(string.IsNullOrEmpty(xml))
                return null;
            //Debug.Print(xml.Length);
            //Debug.WriteLine(xml);
            List<string> list = new List<string>();
            XmlDocument xdoc = new XmlDocument();
            try
            {
                xdoc.LoadXml(xml);
            }
            catch //(WebException ex)
            {
                xdoc.LoadXml(xml);
            }
            XmlNode cnode = xdoc.SelectSingleNode("/eSearchResult/Count");
            if(cnode ==null)
                return null;
            int total = int.Parse(cnode.InnerText);
            if (total == 0)
            {
                list.Add("-1");

            }
            else
            {
                XmlNodeList nodelist = xdoc.SelectNodes("/eSearchResult/IdList/Id");
                foreach (XmlNode node in nodelist)
                {
                    list.Add(node.InnerText);
                }
            }
            return list;
        }
開發者ID:lijiuning,項目名稱:Spacebuilder_4.2.0.0_src,代碼行數:35,代碼來源:PubMedService.cs

示例13: TestHandleMessage

    public void TestHandleMessage() {
      try {
        ContextStore.AddKey("SoapMethod", "get");

        XmlDocument xDoc = new XmlDocument();
        xDoc.LoadXml(SoapMessages_v201406.GetAccountAlerts);
        XmlElement xRequest = (XmlElement) xDoc.SelectSingleNode("/Example/SOAP/Response");
        xDoc.LoadXml(xRequest.InnerText);
        AlertService service = (AlertService) user.GetService(AdWordsService.v201406.AlertService);

        AdWordsCallListener.Instance.HandleMessage(xDoc, service, SoapMessageDirection.IN);

        Assert.AreEqual(user.GetTotalOperationCount(), 2);
        Assert.AreEqual(user.GetOperationCountForLastCall(), 2);
        ApiCallEntry[] callEntries = user.GetCallDetails();
        Assert.AreEqual(callEntries.Length, 1);
        ApiCallEntry callEntry = user.GetCallDetails()[0];

        Assert.AreEqual(callEntry.OperationCount, 2);
        Assert.AreEqual(callEntry.Method, "get");
        Assert.AreEqual(callEntry.Service.Signature.ServiceName, "AlertService");
      } finally {
        ContextStore.RemoveKey("SoapMethod");
      }
    }
開發者ID:psmacchia,項目名稱:googleads-dotnet-lib,代碼行數:25,代碼來源:AdWordsCallListenerTest.cs

示例14: VariantDefinition

 public VariantDefinition(VariantVersion version)
 {
     XmlDocument doc = new XmlDocument();
     if (version.Definition != string.Empty)
         doc.LoadXml(version.Definition);
     else
         doc.LoadXml("<game><board viewBox=\"0 0 100 100\"/></game>");
     Version = version;
     Xml = doc;
 }
開發者ID:rbanna01,項目名稱:Chessmaker,代碼行數:10,代碼來源:VariantDefinition.cs

示例15: ParseXml

        public static XmlNode ParseXml(string xml, bool isDoc)
        {
            XmlDocument doc = new XmlDocument();

            if (isDoc)
                doc.LoadXml(xml);
            else
                doc.LoadXml("<root>" + xml + "</root>");

            return doc.DocumentElement;
        }
開發者ID:noear,項目名稱:Weed3,代碼行數:11,代碼來源:XDom.Ext.cs


注:本文中的System.Xml.XmlDocument.LoadXml方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。