【问题标题】:AvalonEdit - XMLFolding -> Ignore the first lineAvalonEdit - XMLFolding -> 忽略第一行
【发布时间】:2025-12-29 13:55:06
【问题描述】:

在尝试更新折叠时是否可以忽略第一行?

Ignore this line
<?xml version="1.0" encoding="UTF-8"?>
<note>
   <to>Tove</to>
   <from>Jani</Ffrom>
   <heading>Reminder</heading>
   <body>Don't forget me this weekend!</body>
</note>

现在这不是一个有效的 XMLDocument,阅读器会抛出一个异常。

【问题讨论】:

    标签: c# xml parsing avalonedit


    【解决方案1】:

    以下将跳过第一行

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Xml.Linq;
    using System.IO;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            const string FILENAME = @"c:\temp\test.xml";
            static void Main(string[] args)
            {
                StreamReader reader = new StreamReader(FILENAME);
                reader.ReadLine(); // skip first line
    
                XDocument doc = XDocument.Load(reader);
            }
        }
    }
    

    【讨论】:

    • 不是我想要的,但足够好,谢谢。为了让它与 avalon 编辑一起工作,您必须实现您的自定义 UpdateFoldings 和 CreateNewFoldings