Writing to XML

Writing objects to XAML in XML form is a common activity. Because XamlObjectReader doesn’t support WPF-style objects, Listing 21.4 demonstrates converting from XML to XML by pairing up XamlXmlReader with XamlXmlWriter. This may sound nonsensical, but the combination produces a simple “XAML scrubber” that normalizes the input XML to produce consistently represented, consistently spaced XML with comments removed.

LISTING 21.4 A “XAML Scrubber” That Normalizes the Input XML

public static string RewriteXaml(string xmlString){  // String -> TextReader -> XamlXmlReader  using (TextReader textReader = new StringReader(xmlString))  using (XamlXmlReader reader = new XamlXmlReader(textReader))  // TextWriter ...

Get XAML Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.