示例#1
0
        /// <summary>
        /// Parse header from <paramref name="text"/> string
        /// and return position to next character after header.
        /// </summary>
        /// <param name="text">String that will be parsed</param>
        /// <param name="header">Result of parsing</param>
        /// <returns>Position to next character after header</returns>
        /// <exception cref="ParseException">Throw if document has invalid structure</exception>
        private int ParseHeader(string text, out SchemaHeader header)
        {
            header = null;

            var startPosition = NextElementStartPosition(text, 0);

            if (IsEOF(text, startPosition))
            {
                throw new ParseException("Xml document should contain root level element", startPosition);
            }

            var match = _headerRx.Match(text);

            if (!match.Success)
            {
                return(0);
            }

            if (match.Index != 0 || match.Index != startPosition)
            {
                throw new ParseException("Header must be first thing in file", match.Index);
            }

            var builder = BuilderFactory.Create();

            builder.SetValue(match.Value);
            header = builder.BuildHeader();

            return(match.Length);
        }
示例#2
0
 public XmlSchema(SchemaElement root, SchemaHeader header = null,
                  List <SchemaComment> commentsBeforeRoot = null, List <SchemaComment> commentsAfterRoot = null)
     : base(root)
 {
     Header             = header;
     CommentsBeforeRoot = commentsBeforeRoot;
     CommentsAfterRoot  = commentsAfterRoot;
 }
示例#3
0
        private string StringifyHeader(SchemaHeader header)
        {
            if (header != null)
            {
                var headerValue = RemoveNewLineSymbols(header.Value);
                return($"{headerValue}{Environment.NewLine}");
            }

            return(string.Empty);
        }