예제 #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);
        }
예제 #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);
                }
            }
        }
    }
예제 #4
0
 public XmlFixedException(XmlFixData data)
 {
     this.XmlFixData = data;
 }
예제 #5
0
 public bool ComesAfter(XmlFixData other)
 {
     if (LineNumber > other.LineNumber)
         return true;
     if (LineNumber == other.LineNumber && LinePosition > other.LinePosition)
         return true;
     return false;
 }
예제 #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;
        }
예제 #7
0
 public XmlFixedException(XmlFixData data)
 {
     this.XmlFixData = data;
 }