/// <summary> /// Indents the specified line based on the current depth of the XML hierarchy. /// </summary> /// <param name="p_txaTextArea">The text area containing the line to indent.</param> /// <param name="p_intLineNumber">The line number of the line to indent.</param> /// <returns>The indent depth of the specified line.</returns> protected override int AutoIndentLine(TextArea p_txaTextArea, int p_intLineNumber) { var stkTags = XmlParser.ParseTags(p_txaTextArea.Document, p_intLineNumber, null, null); var intDepth = 0; var intLastLineNum = -1; while (stkTags.Count > 0) { if (stkTags.Peek().LineNumber != intLastLineNum) { intLastLineNum = stkTags.Peek().LineNumber; intDepth++; } stkTags.Pop(); } var stbLineWithIndent = new StringBuilder(); for (var i = 0; i < intDepth; i++) { stbLineWithIndent.Append("\t"); } stbLineWithIndent.Append(TextUtilities.GetLineAsString(p_txaTextArea.Document, p_intLineNumber).Trim()); var oldLine = p_txaTextArea.Document.GetLineSegment(p_intLineNumber); var intCaretOffset = stbLineWithIndent.Length - oldLine.Length; SmartReplaceLine(p_txaTextArea.Document, oldLine, stbLineWithIndent.ToString()); p_txaTextArea.Caret.Column += intCaretOffset; return(intDepth); }
/// <summary> /// Generates the list of markers indicating where the XML should be folded. /// </summary> /// <param name="document">The document to fold.</param> /// <param name="fileName">The file name of the document to fold.</param> /// <param name="parseInformation">User-supplied parse information.</param> /// <returns>The list of markers indicating where the XML should be folded.</returns> public List <FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation) { m_lstFolds.Clear(); XmlParser.ParseTags(document, document.TotalNumberOfLines - 1, AddFold, null); return(m_lstFolds); }
/// <summary> /// Validates the XML against the schema. /// </summary> /// <returns><lang langref="true" /> if the XML is valid; <lang langref="false" /> otherwise.</returns> public bool ValidateXml() { m_tmrValidator.Stop(); var docDocument = ActiveTextAreaControl.TextArea.Document; docDocument.MarkerStrategy.RemoveAll(x => { return(x.TextMarkerType == TextMarkerType.WaveLine); }); m_booMalformedXml = false; if (docDocument.TextLength == 0) { return(true); } var stkBadTags = XmlParser.ParseTags(docDocument, docDocument.TotalNumberOfLines - 1, null, HighlightMalformedTag); //this deals with extra tags at beginning of file if ((stkBadTags.Count > 0) || m_booMalformedXml) { while (stkBadTags.Count > 0) { var tpsTag = stkBadTags.Pop(); var tlcStart = new TextLocation(tpsTag.Column, tpsTag.LineNumber); var tlcEnd = new TextLocation(tpsTag.Column + tpsTag.Name.Length, tpsTag.LineNumber); HighlightMalformedTag(docDocument, tpsTag.Name, tlcStart, tlcEnd); } return(false); } var intBadLineNum = Int32.MaxValue; using (var xrdValidator = XmlReader.Create(new StringReader(Text), m_xrsSettings)) { try { while (xrdValidator.Read()) { } if (m_booMalformedXml) { return(false); } } catch (XmlException err2) { intBadLineNum = err2.LineNumber; HighlightValidationErrors(err2.Message, new TextLocation(err2.LinePosition - 1, err2.LineNumber - 1)); } finally { xrdValidator.Close(); } } for (var i = intBadLineNum; i < docDocument.TotalNumberOfLines; i++) { var strLine = docDocument.GetText(docDocument.GetLineSegment(i)); var intLastOpenPos = strLine.LastIndexOf('<'); if (intLastOpenPos < 0) { continue; } var intLastClosePos = strLine.LastIndexOf('>'); if ((intLastClosePos > -1) && (intLastOpenPos > intLastClosePos)) { var stbLines = new StringBuilder(strLine); //there is an open tag on this line - read lines until it is closed. for (; i < docDocument.TotalNumberOfLines; i++) { var strNextLine = docDocument.GetText(docDocument.GetLineSegment(i)); intLastClosePos = strLine.LastIndexOf('>'); stbLines.Append(strNextLine); if (intLastClosePos < 0) { i--; break; } } strLine = stbLines.ToString(); } var mclLineTags = rgxTagContents.Matches(strLine); foreach (Match mtcTag in mclLineTags) { var strTag = mtcTag.Groups[1].Value.Trim(); if (strTag.StartsWith("/")) { HighlightValidationErrors("Unexpected end tag.", new TextLocation(mtcTag.Groups[1].Index + 1, i)); } else { HighlightValidationErrors("Invalid tag.", new TextLocation(mtcTag.Groups[1].Index, i)); } } } return(intBadLineNum == Int32.MaxValue); }