Example #1
0
 public bool ComesAfter(XmlFixData other)
 {
     if (LineNumber > other.LineNumber)
     {
         return(true);
     }
     if (LineNumber == other.LineNumber && LinePosition > other.LinePosition)
     {
         return(true);
     }
     return(false);
 }
        XmlDoctorStatus TryFixOnePass(string xml, out XmlFixData data)
        {
            try
            {
                InitializePass(xml);

                using (var textReader = new StringReader(passXml))
                    using (XmlReader reader = XmlReader.Create(textReader))
                    {
                        while (true)
                        {
                            bool read = reader.Read();
                            if (!read)
                            {
                                break;
                            }
                            HandleNode(reader);
                        }
                    }
            }
            catch (XmlFixedException ex)
            {
                // Success - a fix was made.
                data = ex.XmlFixData;
                return(XmlDoctorStatus.FixMade);
            }
            catch (Exception ex)
            {
                // Failure - the file was not fixed and could not be parsed.
                Debug.WriteLine("Fix Failed: " + ex.ToString());
                data = null;
                return(XmlDoctorStatus.FixFailed);
            }
            finally
            {
                EndPass();
            }
            // No fix needed.
            data = null;
            return(XmlDoctorStatus.NoFixNeeded);
        }
Example #3
0
    public XmlDoctorStatus TryFix(out string newXml)
    {
        XmlFixData data = null;

        while (true)
        {
            XmlFixData newData;
            var        status = TryFixOnePass((data == null ? OriginalXml : data.FixedXml), out newData);
            switch (status)
            {
            case XmlDoctorStatus.FixFailed:
                Debug.WriteLine("Could not fix XML");
                newXml = OriginalXml;
                return(XmlDoctorStatus.FixFailed);

            case XmlDoctorStatus.FixMade:
                if (data != null && !newData.ComesAfter(data))
                {
                    Debug.WriteLine("Warning -- possible infinite loop detected, aborting fix");
                    newXml = OriginalXml;
                    return(XmlDoctorStatus.FixFailed);
                }
                data = newData;
                break;          // Try to fix more

            case XmlDoctorStatus.NoFixNeeded:
                if (data == null)
                {
                    newXml = OriginalXml;
                    return(XmlDoctorStatus.NoFixNeeded);
                }
                else
                {
                    newXml = data.FixedXml;
                    return(XmlDoctorStatus.FixMade);
                }
            }
        }
    }
Example #4
0
 public XmlFixedException(XmlFixData data)
 {
     this.XmlFixData = data;
 }
Example #5
0
 public bool ComesAfter(XmlFixData other)
 {
     if (LineNumber > other.LineNumber)
         return true;
     if (LineNumber == other.LineNumber && LinePosition > other.LinePosition)
         return true;
     return false;
 }
Example #6
0
        XmlDoctorStatus TryFixOnePass(string xml, out XmlFixData data)
        {
            try
            {
                InitializePass(xml);

                using (var textReader = new StringReader(passXml))
                using (XmlReader reader = XmlReader.Create(textReader))
                {
                    while (true)
                    {
                        bool read = reader.Read();
                        if (!read)
                            break;
                        HandleNode(reader);
                    }
                }
            }
            catch (XmlFixedException ex)
            {
                // Success - a fix was made.
                data = ex.XmlFixData;
                return XmlDoctorStatus.FixMade;
            }
            catch (Exception ex)
            {
                // Failure - the file was not fixed and could not be parsed.
                Debug.WriteLine("Fix Failed: " + ex.ToString());
                data = null;
                return XmlDoctorStatus.FixFailed;
            }
            finally
            {
                EndPass();
            }
            // No fix needed.
            data = null;
            return XmlDoctorStatus.NoFixNeeded;
        }
Example #7
0
 public XmlFixedException(XmlFixData data)
 {
     this.XmlFixData = data;
 }