* xmlTextWriterEndElement: * @writer: the xmlTextWriterPtr * * End the current xml element. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */
| 1108 | * Returns the bytes written (may be 0 because of buffering) or -1 in case of error |
| 1109 | */ |
| 1110 | int |
| 1111 | xmlTextWriterEndElement(xmlTextWriterPtr writer) |
| 1112 | { |
| 1113 | int count; |
| 1114 | int sum; |
| 1115 | xmlLinkPtr lk; |
| 1116 | xmlTextWriterStackEntry *p; |
| 1117 | |
| 1118 | if (writer == NULL) |
| 1119 | return -1; |
| 1120 | |
| 1121 | lk = xmlListFront(writer->nodes); |
| 1122 | if (lk == 0) { |
| 1123 | xmlListDelete(writer->nsstack); |
| 1124 | writer->nsstack = NULL; |
| 1125 | return -1; |
| 1126 | } |
| 1127 | |
| 1128 | p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); |
| 1129 | if (p == 0) { |
| 1130 | xmlListDelete(writer->nsstack); |
| 1131 | writer->nsstack = NULL; |
| 1132 | return -1; |
| 1133 | } |
| 1134 | |
| 1135 | sum = 0; |
| 1136 | switch (p->state) { |
| 1137 | case XML_TEXTWRITER_ATTRIBUTE: |
| 1138 | count = xmlTextWriterEndAttribute(writer); |
| 1139 | if (count < 0) { |
| 1140 | xmlListDelete(writer->nsstack); |
| 1141 | writer->nsstack = NULL; |
| 1142 | return -1; |
| 1143 | } |
| 1144 | sum += count; |
| 1145 | /* fallthrough */ |
| 1146 | case XML_TEXTWRITER_NAME: |
| 1147 | /* Output namespace declarations */ |
| 1148 | count = xmlTextWriterOutputNSDecl(writer); |
| 1149 | if (count < 0) |
| 1150 | return -1; |
| 1151 | sum += count; |
| 1152 | |
| 1153 | if (writer->indent) /* next element needs indent */ |
| 1154 | writer->doindent = 1; |
| 1155 | count = xmlOutputBufferWriteString(writer->out, "/>"); |
| 1156 | if (count < 0) |
| 1157 | return -1; |
| 1158 | sum += count; |
| 1159 | break; |
| 1160 | case XML_TEXTWRITER_TEXT: |
| 1161 | if ((writer->indent) && (writer->doindent)) { |
| 1162 | count = xmlTextWriterWriteIndent(writer); |
| 1163 | sum += count; |
| 1164 | writer->doindent = 1; |
| 1165 | } else |
| 1166 | writer->doindent = 1; |
| 1167 | count = xmlOutputBufferWriteString(writer->out, "</"); |
no test coverage detected