예제 #1
0
        }//Stringify().

        //
        //
        private void Stringify(int level, ref StringBuilder s)
        {
            // Nice to read indenting for elements.
            if (level > 0)
            {
                s.Append("\r\n");
            }
            for (int i = 0; i < level; ++i)
            {
                s.Append("    ");
            }

            // Starting tag:
            s.AppendFormat("<{0}", this.Name);
            foreach (string attributeKey in this.Attributes.Keys)
            {
                s.AppendFormat(" {0}={1}", attributeKey, this.Attributes[attributeKey]);
            }


            // sub-Elements
            if (this.SubElements == null || this.SubElements.Count > 0)
            {
                s.Append(">");
                foreach (IStringifiable element in this.SubElements)
                {
                    if (element is Node)
                    {
                        ((Node)element).Stringify(level + 1, ref s);
                    }
                    else
                    {
                        s.AppendFormat("{0}", Stringifiable.Stringify(element));
                    }
                }
                // Ending tag
                s.AppendFormat("</{0}>", this.Name);
            }
            else
            {   // If there are no sub elements we can use the "complete" tag format for this object.
                s.Append("/>");
            }
        }// Stringify()