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


C# Xml.XmlException类代码示例

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


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

示例1: v3

 public int v3()
 {
     Exception inner = new Exception();
     XmlException e = new XmlException("error", inner, 14, 36);
     CompareException(e, "Xml_UserException", inner, 14, 36);
     return TEST_PASS;
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:XmlException.cs

示例2: XmlValidationError

 public XmlValidationError( XmlException ex )
 {
     LineNumber = ex.LineNumber;
     LinePosition = ex.LinePosition;
     Message = ex.Message;
     Severity = XmlSeverityType.Error;
 }
开发者ID:spate,项目名称:Dredmor-XML-Validator,代码行数:7,代码来源:XmlValidationError.cs

示例3: BuildEventFileInfo

 internal BuildEventFileInfo(XmlException e)
 {
   ErrorUtilities.VerifyThrow(e != null, "Need exception context.");
   this.file = e.SourceUri.Length == 0 ? string.Empty : new Uri(e.SourceUri).LocalPath;
   this.line = e.LineNumber;
   this.column = e.LinePosition;
   this.endLine = 0;
   this.endColumn = 0;
 }
开发者ID:nixgupta,项目名称:SolutionReader,代码行数:9,代码来源:BuildEventFileInfo.cs

示例4: CheckXmlException

        protected void CheckXmlException(string expectedCode, XmlException e, int expectedLine, int expectedPosition)
        {
            string actualCode = expectedCode;
            CError.WriteLine("***Exception");
            CError.WriteLineIgnore(e.ToString());
            CError.Compare(e.LineNumber, expectedLine, "CheckXmlException:LineNumber");
            CError.Compare(e.LinePosition, expectedPosition, "CheckXmlException:LinePosition");

            CError.Compare(actualCode, expectedCode, "ec" + e.Message);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:CDataReaderTestCase.cs

示例5: ThrowXmlException

 static public void ThrowXmlException(XmlDictionaryReader reader, XmlException exception)
 {
     string s = exception.Message;
     IXmlLineInfo lineInfo = reader as IXmlLineInfo;
     if (lineInfo != null && lineInfo.HasLineInfo())
     {
         s += " " + SR.Format(SR.XmlLineInfo, lineInfo.LineNumber, lineInfo.LinePosition);
     }
     throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(s));
 }
开发者ID:neris,项目名称:corefx,代码行数:10,代码来源:XmlExceptionHelper.cs

示例6: CreateGuideEntry

        /// <summary>
        /// Creates the guide entry from the given text and relvant attributes
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="hiddenStatus"></param>
        /// <param name="style"></param>
        /// <param name="editing"></param>
        /// <returns></returns>
        static public XmlElement CreateGuideEntry(string text, int hiddenStatus, GuideEntryStyle style, int canRead)
        {

            XmlDocument doc = new XmlDocument();
            if (hiddenStatus > 0 && canRead == 0)
            {
                doc.LoadXml("<GUIDE><BODY>This article has been hidden pending moderation.</BODY></GUIDE>");
            }
            else
            {
                try
                {
                    switch (style)
                    {
                        case GuideEntryStyle.GuideML:
                            text = text.Trim();
                            text = Entities.ReplaceEntitiesWithNumericValues(text);
                            //text = HtmlUtils.ReplaceCRsWithBRs(text);
                            text = HtmlUtils.EscapeNonEscapedAmpersands(text);
                            doc.PreserveWhitespace = true;
                            doc.LoadXml(text);
                            AdjustFootnotes(doc);
                            //doc["GUIDE"]["BODY"].InnerXml = HtmlUtils.ReplaceCRsWithBRs(doc["GUIDE"]["BODY"].InnerXml);
                            break;

                        case GuideEntryStyle.PlainText:
                            doc.LoadXml(StringUtils.PlainTextToGuideML(text));
                            break;

                        case GuideEntryStyle.Html:
                            doc.LoadXml("<GUIDE><BODY><PASSTHROUGH><![CDATA[" + text + "]]></PASSTHROUGH></BODY></GUIDE>");
                            break;

                        default:
                            goto case GuideEntryStyle.GuideML;//null styles are generally guideml...
                        //throw new NotImplementedException("Don't know what type of entry we've got here!");
                    }
                }
                catch (XmlException e)
                {
                    //If something has gone wrong log stuff
                    DnaDiagnostics.Default.WriteExceptionToLog(e);

                    var errorMessage = Regex.Replace(e.Message, "position +[0-9][0-9]* ", "", RegexOptions.IgnoreCase);

                    var xmlException = new XmlException(errorMessage, e);

                    throw new ApiException("GuideML Transform Failed", xmlException);
                }
            }

            return doc.DocumentElement;
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:61,代码来源:GuideEntry.cs

示例7: CompareException

 private void CompareException(XmlException e, string ec, Exception inner, int ln, int lp)
 {
     CError.WriteLine(e);
     CError.Compare((object)e.InnerException, (object)inner, "InnerException");
     CError.Compare(e.LineNumber, ln, "LineNumber");
     CError.Compare(e.LinePosition, lp, "LinePosition");
     string s1 = e.StackTrace;
     Type t = e.GetType();
     Exception e2 = e.GetBaseException();
     int i = e.GetHashCode();
     CError.Compare(!String.IsNullOrEmpty(e.Message), "Message");
     string s3 = e.ToString();
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:13,代码来源:XmlException.cs

示例8: DoScratch

        public void DoScratch()
        {
            try {

              //  int i = Int32.Parse("22r");

                XmlException x = new XmlException("Blah error", null, 25, 100);
                throw x;
            }
            catch (XmlException e) {
                Console.WriteLine("Line Number {0}", e.LineNumber);
                Console.WriteLine("Line Position {0}", e.LinePosition);
                Console.WriteLine("Source URI {0}", e.SourceUri);
                Console.WriteLine("Message {0}", e.Message);
                Console.WriteLine("Stack Trace {0}", e.StackTrace);

            }

            catch (FormatException e) {
                Console.WriteLine("Caught Format Exception");

                Console.WriteLine("Helplink {0}", e.HelpLink);
                Console.WriteLine("Message {0}", e.Message);
                Console.WriteLine("Source {0}", e.Source);
                //Console.WriteLine(" {0}");
                //Console.WriteLine(" {0}");
                //Console.WriteLine(" {0}");
                //Console.WriteLine(" {0}");
                //Console.WriteLine(" {0}");

                if (e.Data != null) {
                    Console.WriteLine("Getting extra details");
                    foreach (DictionaryEntry item in e.Data) {
                        Console.WriteLine("The key is '{0}' and the value is: {1}", item.Key, item.Value);
                    }
                }
            }
            catch (Exception e) {
                Console.WriteLine("Caught Exception");
                if (e.Data != null) {
                    foreach (DictionaryEntry item in e.Data) {
                        Console.WriteLine("The key is '{0}' and the value is: {1}", item.Key, item.Value);
                    }
                }
            }
        }
开发者ID:MichaelRoop,项目名称:NET_TestHarness,代码行数:46,代码来源:Scratch.cs

示例9: BuildXmlErrorMessage

        private static string BuildXmlErrorMessage(string fileName, XmlException exception)
        {
            string msg = Path.GetFileName(fileName) + " is not wel-formed." + Environment.NewLine +
                         "Line " + exception.LineNumber + " at position " + exception.LinePosition + Environment.NewLine +
                         exception.Message;

            var lines = File.ReadAllLines(fileName);
            if (exception.LineNumber >= 0 && exception.LineNumber < lines.Count())
            {
                msg += Environment.NewLine + Environment.NewLine;
                if (exception.LineNumber > 1)
                    msg += (exception.LineNumber - 1) + ":  " + lines[exception.LineNumber - 2] + Environment.NewLine;
                if (exception.LineNumber > 0)
                    msg += (exception.LineNumber) + ":  " + lines[exception.LineNumber - 1] + Environment.NewLine;
                msg += (exception.LineNumber + 1) + ":  " + lines[exception.LineNumber];
            }
            return msg;
        }
开发者ID:LeonCheung,项目名称:subtitleedit,代码行数:18,代码来源:XmlDictionariesTest.cs

示例10: SetUpFixture

		public void SetUpFixture()
		{
			List<string> dialogs = new List<string>();
			dialogs.Add("WelcomeDialog");
			dialogs.Add("ProgressDialog");
			wixDocumentFileName = @"C:\Projects\Test\setup.wxs";
			using (SetupDialogListView control = new SetupDialogListView()) {
				control.AddDialogs(wixDocumentFileName, new ReadOnlyCollection<string>(dialogs));
				
				hasErrorsAtStart = control.HasErrors;
				XmlException xmlEx = new XmlException("Error occurred", null, 10, 5);
				control.AddError(wixDocumentFileName, xmlEx);
				Exception ex = new Exception("Error");
				control.AddError(wixDocumentFileName);
				nodesAdded = control.Items.Count;
				
				SetupDialogListViewItem welcomeDialogListItem = (SetupDialogListViewItem)control.Items[0];
				welcomeDialogText = welcomeDialogListItem.Text;
				welcomeDialogId = welcomeDialogListItem.Id;
				welcomeDialogFileName = welcomeDialogListItem.FileName;

				SetupDialogListViewItem progressDialogListItem = (SetupDialogListViewItem)control.Items[1];
				progressDialogText = progressDialogListItem.Text;
				progressDialogId = progressDialogListItem.Id;
				progressDialogFileName = progressDialogListItem.FileName;
				
				SetupDialogErrorListViewItem xmlErrorDialogListItem = (SetupDialogErrorListViewItem)control.Items[2];
				xmlErrorDialogText = xmlErrorDialogListItem.Text;
				xmlErrorDialogErrorLine = xmlErrorDialogListItem.Line;
				xmlErrorDialogErrorColumn = xmlErrorDialogListItem.Column;
				xmlErrorDialogTextColour = xmlErrorDialogListItem.ForeColor;
				xmlErrorDialogTextBackColour = xmlErrorDialogListItem.BackColor;

				SetupDialogErrorListViewItem errorDialogListItem = (SetupDialogErrorListViewItem)control.Items[3];
				errorDialogText = errorDialogListItem.Text;
				errorDialogErrorLine = errorDialogListItem.Line;
				errorDialogErrorColumn = errorDialogListItem.Column;
				errorDialogTextColour = errorDialogListItem.ForeColor;				
				errorDialogTextBackColour = errorDialogListItem.BackColor;
				
				hasErrors = control.HasErrors;
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:43,代码来源:AddDialogsToSetupDialogListTestFixture.cs

示例11: FormatXmlErrorMessageFromExceptionMessage

 /// <summary>
 /// Helper method that parses Xml Exception messages to dna meesages
 /// </summary>
 /// <param name="ex">The Xml Exception</param>
 /// <returns>The dna mundged version</returns>
 private static string FormatXmlErrorMessageFromExceptionMessage(XmlException ex)
 {
     string errorMessage = "";
     string exceptionMessge = ex.Message;
     int comma = exceptionMessge.IndexOf(',');
     int fullstop = exceptionMessge.IndexOf('.');
     if (fullstop < comma)
     {
         errorMessage = exceptionMessge.Substring(0, fullstop);
     }
     else
     {
         errorMessage = exceptionMessge.Substring(0, comma);
         comma = exceptionMessge.IndexOf(',', comma + 1);
         if (fullstop > comma && comma != -1)
         {
             errorMessage += exceptionMessge.Substring(comma, fullstop - comma);
         }
     }
     return errorMessage + " on line " + ex.LineNumber.ToString();
 }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:26,代码来源:HtmlUtils.cs

示例12: ShowXmlNotWellFormed

        public void ShowXmlNotWellFormed()
        {
            XmlException ex = new XmlException("Message");
            treeViewContainer.ShowXmlIsNotWellFormedMessage(ex);

            Assert.AreEqual(0, treeView.Nodes.Count, "TreeView should be cleared.");
            Assert.AreEqual(ex.Message, treeViewContainer.ErrorMessage);
            Assert.AreEqual(0, splitContainer.Panel2.Controls.IndexOf(errorMessageTextBox), "ErrorMessageTextBox should be on top");
            Assert.AreEqual(ex.Message, errorMessageTextBox.Text);
            Assert.IsTrue(errorMessageTextBox.TabStop);
            Assert.IsFalse(attributesGrid.TabStop);
            Assert.IsFalse(textBox.TabStop);
        }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:13,代码来源:XmlTreeViewContainerTests.cs

示例13: ReadXml

        private void ReadXml()
        {
            try
            {
                XmlReader xmlReader = XmlReader.Create(_streamReader, InternalDeserializer.XmlReaderSettingsForCliXml);
                Deserializer des = new Deserializer(xmlReader);
                while (!des.Done())
                {
                    string streamName;
                    object obj = des.Deserialize(out streamName);

                    //Decide the stream to which data belongs
                    MinishellStream stream = MinishellStream.Unknown;
                    if (streamName != null)
                    {
                        stream = StringToMinishellStreamConverter.ToMinishellStream(streamName);
                    }
                    if (stream == MinishellStream.Unknown)
                    {
                        stream = _isOutput ? MinishellStream.Output : MinishellStream.Error;
                    }

                    //Null is allowed only in output stream
                    if (stream != MinishellStream.Output && obj == null)
                    {
                        continue;
                    }

                    if (stream == MinishellStream.Error)
                    {
                        if (obj is PSObject)
                        {
                            obj = ErrorRecord.FromPSObjectForRemoting(PSObject.AsPSObject(obj));
                        }
                        else
                        {
                            string errorMessage = null;
                            try
                            {
                                errorMessage = (string)LanguagePrimitives.ConvertTo(obj, typeof(string), CultureInfo.InvariantCulture);
                            }
                            catch (PSInvalidCastException)
                            {
                                continue;
                            }
                            obj = new ErrorRecord(new RemoteException(errorMessage),
                                                "NativeCommandError", ErrorCategory.NotSpecified, errorMessage);
                        }
                    }
                    else if (stream == MinishellStream.Information)
                    {
                        if (obj is PSObject)
                        {
                            obj = InformationRecord.FromPSObjectForRemoting(PSObject.AsPSObject(obj));
                        }
                        else
                        {
                            string messageData = null;
                            try
                            {
                                messageData = (string)LanguagePrimitives.ConvertTo(obj, typeof(string), CultureInfo.InvariantCulture);
                            }
                            catch (PSInvalidCastException)
                            {
                                continue;
                            }

                            obj = new InformationRecord(messageData, null);
                        }
                    }
                    else if (stream == MinishellStream.Debug ||
                             stream == MinishellStream.Verbose ||
                             stream == MinishellStream.Warning)
                    {
                        //Convert to string
                        try
                        {
                            obj = LanguagePrimitives.ConvertTo(obj, typeof(string), CultureInfo.InvariantCulture);
                        }
                        catch (PSInvalidCastException)
                        {
                            continue;
                        }
                    }
                    AddObjectToWriter(obj, stream);
                }
            }
            catch (XmlException originalException)
            {
                string template = NativeCP.CliXmlError;
                string message = string.Format(
                    null,
                    template,
                    _isOutput ? MinishellStream.Output : MinishellStream.Error,
                    _processPath,
                    originalException.Message);
                XmlException newException = new XmlException(
                    message,
                    originalException);

//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:NativeCommandProcessor.cs

示例14: ShowXmlIsNotWellFormedMessage

 public void ShowXmlIsNotWellFormedMessage(XmlException ex)
 {
     notWellFormedMessageDisplayed = true;
     notWellFormedException = ex;
 }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:5,代码来源:MockXmlTreeView.cs

示例15: LoadData

		private void LoadData ()
		{
			hasht = new Hashtable ();
#if NET_2_0
			hashtm = new Hashtable ();
#endif
			if (fileName != null) {
				stream = File.OpenRead (fileName);
			}

			try {
				xmlReader = null;
				if (stream != null) {
					xmlReader = new XmlTextReader (stream);
				} else if (reader != null) {
					xmlReader = new XmlTextReader (reader);
				}

				if (xmlReader == null) {
					throw new InvalidOperationException ("ResourceReader is closed.");
				}

				xmlReader.WhitespaceHandling = WhitespaceHandling.None;

				ResXHeader header = new ResXHeader ();
				try {
					while (xmlReader.Read ()) {
						if (xmlReader.NodeType != XmlNodeType.Element)
							continue;

						switch (xmlReader.LocalName) {
						case "resheader":
							ParseHeaderNode (header);
							break;
						case "data":
							ParseDataNode (false);
							break;
#if NET_2_0
						case "metadata":
							ParseDataNode (true);
							break;
#endif
						}
					}
#if NET_2_0
				} catch (XmlException ex) {
					throw new ArgumentException ("Invalid ResX input.", ex);
				} catch (Exception ex) {
					XmlException xex = new XmlException (ex.Message, ex, 
						xmlReader.LineNumber, xmlReader.LinePosition);
					throw new ArgumentException ("Invalid ResX input.", xex);
				}
#else
				} catch (Exception ex) {
					throw new ArgumentException ("Invalid ResX input.", ex);
				}
#endif
				header.Verify ();
			} finally {
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:59,代码来源:ResXResourceReader.cs


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