problems with converting string which contains xml code into XmlTextWriter

221 Views Asked by At

I have a string variable Writer that recieves xml code from another window. I need to pass this string to textWriter variable but i dont know how to make it readable by textWriter. I tried to convert it to XmlTextWriter but it dont seem to work. How can it be accepted by textWriter?

textWriter = (XmlTextWriter)XmlTextWriter.Create(new StringBuilder(Writer));
XmlTextWriter textWriter; 

public Question_Redactor(int k, string Writer)
{          
    textWriter =  new XmlTextWriter(Writer);
    InitializeComponent();
}

When the code runs, the following error message is generated:

The system.InvalidCastException: "Unable to cast objects of type" System. Xml. XmlWellFormedWriter "to type" System. Xml. XmlTextWriter"."

1

There are 1 best solutions below

0
On

Did like jdweng suggested and it worked perfectly

XmlWriter testWriter; 

        public Question_Redactor(int k, string Writer)
        {
            StringBuilder builder = new StringBuilder(Writer);
            XmlWriter writer = XmlWriter.Create(builder);
            testWriter = writer;

            InitializeComponent();

          
        }