AvalonEdit:如何修改 xsd 文件以更改元素属性

AvalonEdit : How to modify the xshd file to change elements atrribute

我尝试修改 xshd 文件以在 C# 中以编程方式更改元素 Color 的属性前景。我尝试使用 XmlAtrribute 访问它并更改它,但它没有用。我该如何改变它?下面是我的 xshd 文件

 <?xml version="1.0"?>
<SyntaxDefinition name="Boo" extensions=".boo" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="String" foreground="Red" />
<Color name="Comment" foreground="Green" />

<!-- This is the main ruleset. -->
<RuleSet>
<Span color="Comment" begin="//" />
<Span color="Comment" multiline="true" begin="/\*" end="\*/" />
<Span color="String">
  <Begin>'</Begin>
  <End>'</End>
  <RuleSet>
    <!-- nested span for escape sequences -->
    <Span begin="\" end="." />
  </RuleSet>
</Span>
<Keywords fontWeight="bold" foreground="Green">
  <Word>IF</Word>
  <Word>IFEND</Word>
  <Word>DECLARED</Word>
</Keywords>
<!-- Digits -->
<Rule foreground="Gray">
    \b0[xX][0-9a-fA-F]+  # hex number
    |    \b
    (    \d+(\.[0-9]+)?   #number with optional floating point
    |    \.[0-9]+         #or just starting with floating point
    )
    ([eE][+-]?[0-9]+)? # optional exponent
  </Rule>
<Rule  foreground="Blue">
    \w*-\w*-*\w*
  </Rule>
<Rule foreground="Pink">
    (\w*=\w*)
  </Rule>
 </RuleSet>
</SyntaxDefinition>

使用 LINQ 试试这个:

XDocument doc = XDocument.Load("file.xml");
XNamespace ns = "http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008";
var element = doc.Descendants(ns + "Color").First(x => x.Attribute("name").Value == "String");
element.SetAttributeValue("foreground", "VALUECOLOR");
doc.Save("file.xml");