Example #1
0
        // Returns whole document as a string
        public static string GetData(ElementTree tree)
        {
            if (tree == null || tree.Root == null)
            {
                throw new ArgumentException("Tree cannot be null!");
            }

            return(tree.Root.Data);
        }
Example #2
0
 public void AddRange(ElementTree source)
 {
     if (source != null)
     {
         elements.AddRange(source.elements);
     }
     if (Root == null)
     {
         Root = source.Root;
     }
 }
Example #3
0
        // Builds tree and parses each element
        private static ElementTree BuildTree(DataElementDTO data, RenderOptions options, RenderAccumulator accumulator = null)
        {
            var tree = new ElementTree();

            var acc = accumulator;

            if (accumulator == null)
            {
                acc = new RenderAccumulator();
            }

            if (!string.IsNullOrEmpty(data.Value))
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.Value;

                tree.Add(new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                });
            }

            else if (data.Childs.Any())
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.OpenTag;

                var elementNode = new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                };

                RenderManager.AddTab(acc);

                foreach (var item in data.Childs)
                {
                    var temp = BuildTree(item, options, acc);

                    foreach (var node in temp.Elements)
                    {
                        elementNode.Childs.Add(node);
                        elementNode.Data += node.Data;
                    }
                }

                options.TargetType = RenderTargetTypes.ClosedTag;

                elementNode.Data += RenderManager.Render(tag, options, acc);
                tree.Add(elementNode);
            }

            else
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.BodylessTag;

                tree.Add(new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                });
            }

            RenderManager.RemoveTab(acc);

            return(tree);
        }
Example #4
0
        // Builds tree and parses each element
        private static ElementTree BuildTree(DataElementDTO data, RenderOptions options, RenderAccumulator accumulator = null)
        {
            // Tree, that will exported to SdmlGenerator and will be containing all elements
            var tree = new ElementTree();

            // Recursion accumulator. Allows to render tabulations, based on layer count
            var acc = accumulator;

            if (accumulator == null)
            {
                acc = new RenderAccumulator();
            }

            // If data has value that means this element donesn't have childs
            if (!string.IsNullOrEmpty(data.Value))
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.Value;

                tree.Add(new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                });
            }

            // If data contains at least one child it has to be serialized in a different way than value element
            else if (data.Childs.Any())
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.OpenTag;

                var elementNode = new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                };

                // Add tab to accumulator
                RenderManager.AddTab(acc);

                foreach (var item in data.Childs)
                {
                    var temp = BuildTree(item, options, acc);

                    foreach (var node in temp.Elements)
                    {
                        elementNode.Childs.Add(node);
                        elementNode.Data += node.Data;
                    }
                }

                options.TargetType = RenderTargetTypes.ClosedTag;

                elementNode.Data += RenderManager.Render(tag, options, acc);
                tree.Add(elementNode);
            }

            // If data has no value and no childs it will be rendered as bodyless tag
            else
            {
                var tag = new SdmlTag(data);
                options.TargetType = RenderTargetTypes.BodylessTag;

                tree.Add(new ElementNode()
                {
                    Data    = RenderManager.Render(tag, options, acc),
                    Element = tag,
                    Parent  = new SdmlTag(data.Parent)
                });
            }

            // Removes tabs from accumulator
            RenderManager.RemoveTab(acc);

            return(tree);
        }