Normalize() public method

public Normalize ( ) : void
return void
Esempio n. 1
0
        public virtual void Normalize()
        {
            StringBuilder tmpBuilder = new StringBuilder();
            int           count      = this.ChildNodes.Count;
            int           start      = 0;

            for (int i = 0; i < count; i++)
            {
                XmlNode c = ChildNodes [i];
                switch (c.NodeType)
                {
                case XmlNodeType.Text:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    tmpBuilder.Append(c.Value);
                    break;

                default:
                    c.Normalize();
                    NormalizeRange(start, i, tmpBuilder);
                    // Continue to normalize from next node.
                    start = i + 1;
                    break;
                }
            }
            if (start < count)
            {
                NormalizeRange(start, count, tmpBuilder);
            }
        }
Esempio n. 2
0
        // Normalize the text nodes underneath this node.
        public virtual void Normalize()
        {
            XmlNode       current = NodeList.GetFirstChild(this);
            XmlNode       next, setNode;
            StringBuilder builder = null;

            setNode = null;
            while (current != null)
            {
                next = NodeList.GetNextSibling(this);
                switch (current.NodeType)
                {
                case XmlNodeType.Text:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                {
                    if (setNode != null)
                    {
                        builder.Append(current.Value);
                        RemoveChild(current);
                    }
                    else
                    {
                        setNode = current;
                        builder = new StringBuilder(current.Value);
                    }
                }
                break;

                case XmlNodeType.Element:
                {
                    if (setNode != null)
                    {
                        setNode.Value = builder.ToString();
                        setNode       = null;
                        builder       = null;
                    }
                    current.Normalize();
                }
                break;

                default:
                {
                    if (setNode != null)
                    {
                        setNode.Value = builder.ToString();
                        setNode       = null;
                        builder       = null;
                    }
                }
                break;
                }
                current = next;
            }
            if (setNode != null)
            {
                setNode.Value = builder.ToString();
            }
        }
Esempio n. 3
0
        // DOM Level 2

        // Puts all XmlText nodes in the full depth of the sub-tree
        // underneath this XmlNode into a "normal" form where only
        // markup (e.g., tags, comments, processing instructions, CDATA sections,
        // and entity references) separates XmlText nodes, that is, there
        // are no adjacent XmlText nodes.
        public virtual void Normalize()
        {
            XmlNode       firstChildTextLikeNode = null;
            StringBuilder sb = StringBuilderCache.Acquire();

            for (XmlNode crtChild = this.FirstChild; crtChild != null;)
            {
                XmlNode nextChild = crtChild.NextSibling;
                switch (crtChild.NodeType)
                {
                case XmlNodeType.Text:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                {
                    sb.Append(crtChild.Value);
                    XmlNode winner = NormalizeWinner(firstChildTextLikeNode, crtChild);
                    if (winner == firstChildTextLikeNode)
                    {
                        this.RemoveChild(crtChild);
                    }
                    else
                    {
                        if (firstChildTextLikeNode != null)
                        {
                            this.RemoveChild(firstChildTextLikeNode);
                        }
                        firstChildTextLikeNode = crtChild;
                    }
                    break;
                }

                case XmlNodeType.Element:
                {
                    crtChild.Normalize();
                    goto default;
                }

                default:
                {
                    if (firstChildTextLikeNode != null)
                    {
                        firstChildTextLikeNode.Value = sb.ToString();
                        firstChildTextLikeNode       = null;
                    }
                    sb.Remove(0, sb.Length);
                    break;
                }
                }
                crtChild = nextChild;
            }
            if (firstChildTextLikeNode != null && sb.Length > 0)
            {
                firstChildTextLikeNode.Value = sb.ToString();
            }

            StringBuilderCache.Release(sb);
        }
        public virtual void Normalize()
        {
            XmlNode       firstNode = null;
            XmlNode       nextSibling;
            StringBuilder builder = new StringBuilder();

            for (XmlNode node2 = this.FirstChild; node2 != null; node2 = nextSibling)
            {
                nextSibling = node2.NextSibling;
                switch (node2.NodeType)
                {
                case XmlNodeType.Element:
                    node2.Normalize();
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                {
                    builder.Append(node2.Value);
                    if (this.NormalizeWinner(firstNode, node2) == firstNode)
                    {
                        this.RemoveChild(node2);
                    }
                    else
                    {
                        if (firstNode != null)
                        {
                            this.RemoveChild(firstNode);
                        }
                        firstNode = node2;
                    }
                    continue;
                }
                }
                if (firstNode != null)
                {
                    firstNode.Value = builder.ToString();
                    firstNode       = null;
                }
                builder.Remove(0, builder.Length);
            }
            if ((firstNode != null) && (builder.Length > 0))
            {
                firstNode.Value = builder.ToString();
            }
        }
Esempio n. 5
0
        public void core0001T()
        {
            string computedValue = "";
            string expectedValue = "Roger\n Jones";

            System.Xml.XmlNode          testNode     = null;
            System.Xml.XmlCharacterData testNodeData = null;

            testResults results = new testResults("Core0001T");

            try
            {
                results.description = "If there is no markup language in a block of text, " +
                                      "then the content of the text is contained into " +
                                      "an object implementing the Text interface that is " +
                                      "the only child of the element.";
                //
                // Retrieve the second child of the second employee and access its
                // textual data.
                //
                testNode = util.nodeObject(util.THIRD, util.SECOND);
                testNode.Normalize();
                testNodeData  = (System.Xml.XmlCharacterData)testNode.FirstChild;
                computedValue = testNodeData.Value;
            }
            catch (System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual   = computedValue;

            Assert.AreEqual(results.expected, results.actual);
        }