Example #1
0
        /// <summary>
        ///     Load an <see cref="XDocument"/> with <see cref="Location"/> annotations.
        /// </summary>
        /// <param name="textReader">
        ///     The <see cref="TextReader"/> to read from.
        /// </param>
        /// <returns>
        ///     The <see cref="XDocument"/>.
        /// </returns>
        public static XDocument LoadWithLocations(TextReader textReader)
        {
            XDocument document;

            using (LocatingXmlTextReader xmlReader = new LocatingXmlTextReader(textReader))
            {
                document = XDocument.Load(xmlReader, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
                AddLocations(document.Root,
                             new Queue <Location>(xmlReader._locations)
                             );
            }

            return(document);
        }
Example #2
0
        /// <summary>
        ///     The main program entry-point.
        /// </summary>
        static void Main()
        {
            ConfigureLogging();

            try
            {
                Log.Information("Loading...");
                XDocument document = LocatingXmlTextReader.LoadWithLocations("Test.xml");
                Log.Information("Loaded...");

                Log.Information("=======================================");

                DumpElement(document.Root, depth: 0);
            }
            catch (Exception eUnexpected)
            {
                Log.Error(eUnexpected, eUnexpected.Message);
            }
        }