locked
Looping through Workflow Xaml RRS feed

  • Question

  • Hello Everyone,

    I have been trying to simply loop through one xaml file node by node then write it out in another xaml file node by node at the same time. Sounds easy enough right?  Here is my code that attempts this seemingly simple task.

    (First the xaml file I am reading in)
    <p:Activity mc:Ignorable="" 
                x:Class="TestSequentials.Sequence1" 
                xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design" 
                xmlns:__Sequence1="clr-namespace:TestSequentials;" 
                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities" 
                xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" 
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <p:Sequence x:Name="SequenceActivity1" >
        
      </p:Sequence>
    </p:Activity>


    class Program
        {
            [STAThread]
            static void Main(string[] args)
            {
                string filePath = "Sequence1.xaml";
                string filePathOut = "Sequence1Out.xaml";
                Console.WriteLine("XAML Contents:");
                string xamlContents = File.ReadAllText(filePath);
                Console.WriteLine(xamlContents);
                Console.WriteLine();
                LoopThroughXaml(filePath, filePathOut);
                Console.WriteLine("Hit any key to end application....");
                Console.ReadLine();
            }
    
            //loop through all the XAML nodes in this XAML file.
            private static void LoopThroughXaml(string filePath, string filePathOut)
            {
                XmlReader xr = XmlReader.Create(filePath);
                XmlWriter xw = XmlWriter.Create(filePathOut);
                XamlXmlReader reader = new XamlXmlReader(xr);
                
                XamlSchemaContext xamlSchemaContext = new XamlSchemaContext();
                XamlXmlWriter writer = new XamlXmlWriter(xw, xamlSchemaContext);
    
                while (reader.Read())
                {
                    try
                    {
                        writer.WriteNode(reader);
                    }
                    catch (Exception e)
                    {
                        //eating the exception to get at least some written output for debugging.
                    }
                }
                writer.Flush();
            }
    }
    If you run it you will see that you get a "<p1:base" node that is attempted to be written in which appears to be the root of my problem.  I don't know what that node means or how it is getting in since I am simply reading and then writing a xaml file node by node.  I must admit I have found the new Xaml api to be much less than impressive, and light years from intuitive.  If someone could point out my problem here I would greatly appreciate it.

    Thanks in advance,

    Bob
    Saturday, July 11, 2009 11:57 PM

Answers



  • XmlReader xr = XmlReader.Create(File.OpenText(filePath));



    Thanks
    Roman
    Roman Kiss, MVP Connected System Developer
    Sunday, July 12, 2009 8:40 PM

All replies



  • XmlReader xr = XmlReader.Create(File.OpenText(filePath));



    Thanks
    Roman
    Roman Kiss, MVP Connected System Developer
    Sunday, July 12, 2009 8:40 PM
  • Holy ____, that was it!  You are a freaking genius Roman!

    Thanks a million,

    Bob
    Sunday, July 12, 2009 8:49 PM