Permalink
Browse files

convert elements with no value to empty elements

  • Loading branch information...
1 parent 43e867c commit 17f8c8f1efaa4c364babb711165056a85da13500 @siegfriedpammer siegfriedpammer committed May 25, 2011
@@ -3,11 +3,12 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
+using System.Xml;
using System.Xml.Linq;
-
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
@@ -54,8 +55,21 @@ bool LoadBaml(AvalonEditTextOutput output)
using (XmlBamlReader reader = new XmlBamlReader(bamlStream, new CecilTypeResolver(asm)))
xamlDocument = XDocument.Load(reader);
+ ConvertToEmptyElements(xamlDocument.Root);
+
output.Write(xamlDocument.ToString());
return true;
}
+
+ void ConvertToEmptyElements(XElement element)
+ {
+ foreach (var el in element.Elements()) {
+ if (!el.IsEmpty && !el.HasElements && el.Value == "") {
+ el.RemoveNodes();
+ continue;
+ }
+ ConvertToEmptyElements(el);
+ }
+ }
}
}
@@ -1057,9 +1057,6 @@ private void ReadPropertyListEnd()
private void ReadPropertyComplexEnd()
{
- if (!(elements.Peek() is XmlBamlPropertyElement))
- throw new InvalidCastException();
-
XmlBamlPropertyElement propertyElement = (XmlBamlPropertyElement) elements.Peek();
CloseElement();

0 comments on commit 17f8c8f

Please sign in to comment.