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); }
/// <summary> /// Return a handle to the first child element with the given name. /// </summary> TiXmlHandle FirstChildElement(string value) { if (node != null) { TiXmlElement child = node.FirstChildElement(value); if (child != null) { return(new TiXmlHandle(child)); } } return(new TiXmlHandle()); }
/// <summary> /// Creates a new Element and returns it - the returned element is a copy. /// </summary> public override TiXmlNode Clone() { TiXmlElement clone = new TiXmlElement(Value()); if (clone == null) { return(null); } CopyTo(clone); return(clone); }
/// <summary> /// Return a handle to the "index" child element. /// The first child element is 0, the second 1, etc. Note that only TiXmlElements /// are indexed: other types are not counted. /// </summary> TiXmlHandle ChildElement(int count) { if (node != null) { int i; TiXmlElement child = node.FirstChildElement(); for (i = 0; child != null && i < count; child = child.NextSiblingElement(), ++i) { // nothing } if (child != null) { return(new TiXmlHandle(child)); } } return(new TiXmlHandle()); }
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()); } }
public override bool VisitExit(TiXmlElement element) { --depth; if (element.FirstChild() == null) { // nothing. } else { if (simpleTextPrint) { simpleTextPrint = false; } else { DoIndent(); } buffer.Append("</"); buffer.Append(element.Value()); buffer.Append(">"); DoLineBreak(); } return(true); }
public TiXmlElement(TiXmlElement copy) : base(TiXmlNode.NodeType.ELEMENT) { //firstChild = lastChild = null; copy.CopyTo(this); }
/// <summary> /// Figure out what is at *p, and parse it. Returns null if it is not an xml node. /// </summary> protected TiXmlNode Identify(string p, int index, int encoding) { TiXmlNode returnNode = null; index = SkipWhiteSpace(p, index, encoding); if (p == null || index < 0 || index >= p.Length || p[index] != '<') { return(null); } TiXmlDocument doc = GetDocument(); index = SkipWhiteSpace(p, index, encoding); if (index < 0 || index >= p.Length) { return(null); } // What is this thing? // - Elements start with a letter or underscore, but xml is reserved. // - Comments: <!-- // - Decleration: <?xml // - Everthing else is unknown to tinyxml. // const string xmlHeader = "<?xml"; const string commentHeader = "<!--"; const string dtdHeader = "<!"; const string cdataHeader = "<![CDATA["; if (StringEqual(p, index, xmlHeader, true, encoding)) { #if UNUSED TIXML_LOG("XML parsing Declaration\n"); #endif returnNode = new TiXmlDeclaration(); } else if (StringEqual(p, index, commentHeader, false, encoding)) { #if UNUSED TIXML_LOG("XML parsing Comment\n"); #endif returnNode = new TiXmlComment(); } else if (StringEqual(p, index, cdataHeader, false, encoding)) { #if UNUSED TIXML_LOG("XML parsing CDATA\n"); #endif TiXmlText text = new TiXmlText(""); text.SetCDATA(true); returnNode = text; } else if (StringEqual(p, index, dtdHeader, false, encoding)) { #if UNUSED TIXML_LOG("XML parsing Unknown(1)\n"); #endif returnNode = new TiXmlUnknown(); } else if (IsAlpha(p[index + 1], encoding) || p[index + 1] == '_') { #if UNUSED TIXML_LOG("XML parsing Element\n"); #endif returnNode = new TiXmlElement(""); } else { #if UNUSED TIXML_LOG("XML parsing Unknown(2)\n"); #endif returnNode = new TiXmlUnknown(); } if (returnNode != null) { // Set the parent, so it can report errors returnNode.parent = this; } else { if (doc != null) { doc.SetError(ErrorType.TIXML_ERROR_OUT_OF_MEMORY, null, 0, null, TiXmlEncoding.TIXML_ENCODING_UNKNOWN); } } return(returnNode); }
/// <summary> /// Visit an element. /// </summary> public virtual bool VisitExit(TiXmlElement element) { return(true); }
/// <summary> /// Visit an element. /// </summary> public virtual bool VisitEnter(TiXmlElement element, TiXmlAttribute firstAttribute) { return(true); }