예제 #1
0
        }         // ToTextButtonClick

        // ----------------------------------------------------------------------
        private void ToXmlButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                TextRange conversionText = ConversionText;
                using (MemoryStream stream = new MemoryStream())
                {
                    conversionText.Save(stream, DataFormats.Rtf);
                    stream.Seek(0, SeekOrigin.Begin);
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(reader);

                        XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                        xmlWriterSettings.Indent      = true;
                        xmlWriterSettings.IndentChars = ("  ");
                        StringBuilder sb = new StringBuilder();
                        using (XmlWriter writer = XmlWriter.Create(sb, xmlWriterSettings))
                        {
                            RtfXmlConverter xmlConverter = new RtfXmlConverter(rtfDocument, writer);
                            xmlConverter.Convert();
                            writer.Flush();
                            textBox.Text = sb.ToString();
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(this, "Error " + exception.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }         // ToXmlButtonClick
예제 #2
0
        }         // InterpretRtf

        // ----------------------------------------------------------------------
        private void ConvertXml(IRtfDocument rtfDocument)
        {
            try
            {
                XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                xmlWriterSettings.Indent      = true;
                xmlWriterSettings.IndentChars = ("  ");
                xmlWriterSettings.Encoding    = settings.Encoding;

                string fileName = settings.BuildDestinationFileName(null, RtfXmlConverter.DefaultXmlFileExtension);
                using (XmlWriter writer = XmlWriter.Create(fileName, xmlWriterSettings))
                {
                    RtfXmlConvertSettings xmlConvertSettings = new RtfXmlConvertSettings();
                    xmlConvertSettings.Prefix           = settings.XmlPrefix;
                    xmlConvertSettings.Ns               = settings.XmlNamespace;
                    xmlConvertSettings.IsShowHiddenText = settings.ShowHiddenText;
                    RtfXmlConverter xmlConverter = new RtfXmlConverter(rtfDocument, writer, xmlConvertSettings);
                    xmlConverter.Convert();
                    writer.Flush();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("error while converting to xml: " + e.Message);
                ExitCode = ProgramExitCode.ConvertXml;
            }
        }         // ConvertXml
예제 #3
0
        }         // ToTextButtonClick

        // ----------------------------------------------------------------------
        private void ToXmlButtonClick(object sender, EventArgs e)
        {
            try
            {
                IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(ConversionText);

                XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                xmlWriterSettings.Indent      = true;
                xmlWriterSettings.IndentChars = ("  ");
                StringBuilder sb = new StringBuilder();
                using (XmlWriter writer = XmlWriter.Create(sb, xmlWriterSettings))
                {
                    RtfXmlConverter xmlConverter = new RtfXmlConverter(rtfDocument, writer);
                    xmlConverter.Convert();
                    writer.Flush();
                    textBox.Text = sb.ToString();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(this, "Error " + exception.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }         // ToXmlButtonClick