コード例 #1
0
ファイル: XmlFormatter.cs プロジェクト: ztahlis/Schematron
        /// <summary>
        /// Look at <see cref="IFormatter.Format(Test, XPathNavigator, StringBuilder)"/> documentation.
        /// </summary>
        public override void Format(Test source, XPathNavigator context, StringBuilder output)
        {
            string        msg    = source.Message;
            XmlTextWriter writer = new XmlTextWriter(new StringWriter(output));

            //Temporary disable namespace support.
            writer.Namespaces = false;

            // Start element declaration.
            writer.WriteStartElement("message");

            msg = FormatMessage(source, context, msg).ToString();

            // Finally remove any non-name schematron tag in the message.
            string res = TagExpressions.AllSchematron.Replace(msg, String.Empty);

            //Accumulate namespaces found during traversal of node for its position.
            Hashtable ns = new Hashtable();

            // Write <text> element.
            writer.WriteElementString("text", res);
            // Write <path> element.
            writer.WriteElementString("path", FormattingUtils.GetFullNodePosition(context.Clone(), String.Empty, source, ns));
            // Write <summary> element.
            //writer.WriteElementString("summary", FormattingUtils.GetNodeSummary(context, ns, String.Empty));
            writer.WriteStartElement("summary");
            writer.WriteRaw(FormattingUtils.GetNodeSummary(context, ns, String.Empty));
            writer.WriteEndElement();

            // Write <position> element.
            if (context is IXmlLineInfo)
            {
                writer.WriteStartElement("position");
                IXmlLineInfo info = (IXmlLineInfo)context;
                writer.WriteAttributeString("line", info.LineNumber.ToString());
                writer.WriteAttributeString("column", info.LinePosition.ToString());
                writer.WriteEndElement();
            }

            // Close <message> element.
            writer.WriteEndElement();
            writer.Flush();
        }
コード例 #2
0
        /// <summary>
        /// Look at <see cref="IFormatter.Format(Test, XPathNavigator, StringBuilder)"/> documentation.
        /// </summary>
        public override void Format(Test source, XPathNavigator context, StringBuilder output)
        {
            StringBuilder sb = FormatMessage(source, context, source.Message);

            if (source is Assert)
            {
                sb.Insert(0, "\tAssert fails: ");
            }
            else
            {
                sb.Insert(0, "\tReport: ");
            }

            Hashtable ns = new Hashtable();

            sb.Append("\r\n\tAt: " + FormattingUtils.GetFullNodePosition(context.Clone(), String.Empty, source, ns));
            sb.Append("\r\n");

            output.Append(sb.ToString());
        }
コード例 #3
0
ファイル: LogFormatter.cs プロジェクト: ztahlis/Schematron
        /// <summary>
        /// Look at <see cref="IFormatter.Format(Test, XPathNavigator, StringBuilder)"/> documentation.
        /// </summary>
        public override void Format(Test source, XPathNavigator context, StringBuilder output)
        {
            StringBuilder sb = FormatMessage(source, context, source.Message);
            // Finally remove any non-name schematron tag in the message.
            string res = TagExpressions.AllSchematron.Replace(sb.ToString(), String.Empty);

            sb = new StringBuilder();
            if (source is Assert)
            {
                sb.Append("\tAssert fails: ");
            }
            else
            {
                sb.Append("\tReport: ");
            }
            sb.Append(res);

            //Accumulate namespaces found during traversal of node for its position.
            Hashtable ns = new Hashtable();

            sb.Append("\r\n\tAt: ").Append(FormattingUtils.GetFullNodePosition(context.Clone(), String.Empty, source, ns));
            sb.Append(FormattingUtils.GetNodeSummary(context, ns, "\r\n\t    "));

            res = FormattingUtils.GetPositionInFile(context, "\r\n\t    ");
            if (res != String.Empty)
            {
                sb.Append(res);
            }

            res = FormattingUtils.GetNamespaceSummary(context, ns, "\r\n\t    ");
            if (res != string.Empty)
            {
                sb.Append(res);
            }
            sb.Append("\r\n");
            output.Append(sb.ToString());
        }