示例#1
0
        public override bool VisitEnter(TiXmlElement element, TiXmlAttribute firstAttribute)
        {
            DoIndent();
            buffer.Append("<");
            buffer.Append(element.Value());

            for (TiXmlAttribute attrib = firstAttribute; attrib != null; attrib = attrib.Next())
            {
                buffer.Append(" ");
                attrib.Print(buffer, 0);
            }

            if (element.FirstChild() == null)
            {
                buffer.Append(" />");
                DoLineBreak();
            }
            else
            {
                buffer.Append(">");
                if (element.FirstChild().ToText() != null &&
                    element.LastChild() == element.FirstChild() &&
                    element.FirstChild().ToText().CDATA() == false)
                {
                    simpleTextPrint = true;
                    // no DoLineBreak()!
                }
                else
                {
                    DoLineBreak();
                }
            }
            ++depth;
            return(true);
        }
示例#2
0
        protected void CopyTo(TiXmlElement target)
        {
            // superclass:
            base.CopyTo(target);

            // Element class:
            // Clone the attributes, then clone the children.
            TiXmlAttribute attribute = null;

            for (attribute = attributeSet.First(); attribute != null; attribute = attribute.Next())
            {
                target.SetAttribute(attribute.Name(), attribute.Value());
            }

            TiXmlNode node = null;

            for (node = firstChild; node != null; node = node.NextSibling())
            {
                target.LinkEndChild(node.Clone());
            }
        }
示例#3
0
        /// <summary>
        /// Print the Element to a FILE stream.
        /// </summary>
        public override void Print(StringBuilder cfile, int depth)
        {
            //assert( cfile );
            for (int i = 0; i < depth; i++)
            {
                //fprintf( cfile, "    " );
                cfile.Append("    ");
            }

            cfile.Append("<"); cfile.Append(value);
            //fprintf( cfile, "<%s", value.c_str() );

            for (TiXmlAttribute attrib = attributeSet.First(); attrib != null; attrib = attrib.Next())
            {
                cfile.Append(" ");
                //fprintf(cfile, " ");
                attrib.Print(cfile, depth);
            }

            // There are 3 different formatting approaches:
            // 1) An element without children is printed as a <foo /> node
            // 2) An element with only a text child is printed as <foo> text </foo>
            // 3) An element with children is printed on multiple lines.
            if (firstChild == null)
            {
                //fprintf(cfile, " />");
                cfile.Append(" />");
            }
            else if (firstChild == lastChild && firstChild.ToText() != null)
            {
                //fprintf(cfile, ">");
                cfile.Append(">");
                firstChild.Print(cfile, depth + 1);
                //fprintf(cfile, "</%s>", value.c_str());
                cfile.Append("</"); cfile.Append(value); cfile.Append(">");
            }
            else
            {
                //fprintf(cfile, ">");
                cfile.Append(">");

                for (TiXmlNode node = firstChild; node != null; node = node.NextSibling())
                {
                    if (node.ToText() == null)
                    {
                        //fprintf(cfile, "\n");
                        cfile.Append("\n");
                    }
                    node.Print(cfile, depth + 1);
                }
                //fprintf(cfile, "\n");
                cfile.Append("\n");
                for (int i = 0; i < depth; ++i)
                {
                    //fprintf(cfile, "    ");
                    cfile.Append("    ");
                }
                //fprintf(cfile, "</%s>", value.c_str());
                cfile.Append("</"); cfile.Append(value); cfile.Append(">");
            }
        }