コード例 #1
0
        /// <summary>
        /// Xml loader
        /// </summary>
        /// <param name="xmlData"></param>
        public void LoadXml(string xmlData)
        {
            // if not null
            if (string.IsNullOrWhiteSpace(xmlData))
            {
                MessageBox.Show("XML içeriği boş", "Geçersiz XML Verisi", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            // create xml document
            var xmldoc = new XmlDocument();
            // parse xml data
            var xdoc = XDocument.Parse(xmlData);

            var sw = new Utf8StringWriter();

            xdoc.Save(sw);
            var xdocSb = sw.ToString();

            // load parsed xml data to xml doc
            xmldoc.LoadXml(xdocSb);

            // insert to editor
            AvalonXmlEditor.Text = xdocSb;

            // bind to xml tree
            XmlTree.SetBinding(ItemsControl.ItemsSourceProperty, Xml.BindXmlDocument(xmldoc));
        }
コード例 #2
0
        /// <summary>
        /// XML data reformatter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReFormatXmlString(object sender, RoutedEventArgs e)
        {
            // get data from editor
            var xmlData = AvalonXmlEditor.Text;

            // if not null
            if (string.IsNullOrWhiteSpace(xmlData))
            {
                return;
            }

            // create xml document
            var xmldoc = new XmlDocument();
            // parse xml data
            var xdoc = XDocument.Parse(xmlData).ToString().Trim();

            // load parsed xml data to xml doc
            xmldoc.LoadXml(xdoc);

            // insert to editor
            AvalonXmlEditor.Text = xdoc;

            // bind to xml tree
            XmlTree.SetBinding(ItemsControl.ItemsSourceProperty, Xml.BindXmlDocument(xmldoc));
        }
コード例 #3
0
        /// <summary>
        /// Json to Xml converter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void JsontoXmlConvert(object sender, RoutedEventArgs e)
        {
            // null check
            if (string.IsNullOrEmpty(AvalonJsonEditor.Text))
            {
                MessageBox.Show("Json verisi boş olmamalıdır", "Boş JSON İçeriği", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            // validate json data
            if (!Core.Helpers.Json.Json.IsValidJson(AvalonJsonEditor.Text))
            {
                MessageBox.Show(Core.Helpers.Json.Json.JsonValidationError, "Geçersiz JSON Verisi", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            try
            {
                // convert json to xml
                var newXmlData = Core.Helpers.Json.Json.Json2Xml(AvalonJsonEditor.Text);

                // if not null
                if (string.IsNullOrWhiteSpace(newXmlData))
                {
                    return;
                }

                // create xml document
                var xmldoc = new XmlDocument();
                // parse xml data
                var xdoc = XDocument.Parse(newXmlData).ToString().Trim();
                // load parsed xml data to xml doc
                xmldoc.LoadXml(xdoc);

                // insert to editor
                AvalonXmlEditor.Text = xdoc;

                // bind to xml tree
                XmlTree.SetBinding(ItemsControl.ItemsSourceProperty, Xml.BindXmlDocument(xmldoc));

                // switch xml tab
                TabControl.SelectedIndex = 1;
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString(), "İşlem Başarısız", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
コード例 #4
0
        /// <summary>
        /// On load event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void JXR_Editor_OnLoaded(object sender, RoutedEventArgs e)
        {
            #region Folding

            // set highlighting theme
            foreach (var item in HighlightingComboBox.Items)
            {
                // get highlightings
                var hitem = (IHighlightingDefinition)item;
                // if there is json dark
                switch (hitem.Name)
                {
                case "JsonDark":
                    // set json dark syntaxhighlighting theme
                    AvalonJsonEditor.SyntaxHighlighting = hitem;
                    break;

                case "XMLDark":
                    // set xml dark syntaxhighlighting theme
                    AvalonXmlEditor.SyntaxHighlighting = hitem;
                    break;
                }
            }

            Folding();
            UpdateFoldings();

            #endregion

            // example xml data
            var xmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <Example_List> <Example_Item> <Example_Key>example Value</Example_Key> </Example_Item> <Example_Item> <Example_Key>example Value</Example_Key> </Example_Item> </Example_List>";
            // create xml document
            var xmldoc = new XmlDocument();
            // parse xml data
            var xdoc = XDocument.Parse(xmlData).ToString().Trim();
            // load parsed xml data to xml doc
            xmldoc.LoadXml(xdoc);

            // insert to editor
            AvalonXmlEditor.Text = xdoc;

            // bind to xml tree
            XmlTree.SetBinding(ItemsControl.ItemsSourceProperty, Xml.BindXmlDocument(xmldoc));
        }