📄 xmlwriter.c
字号:
} count = xmlOutputBufferWriteString(writer->out, "<"); if (count < 0) return -1; sum += count; count = xmlOutputBufferWriteString(writer->out, (const char *) p->name); if (count < 0) return -1; sum += count; return sum;}/** * xmlTextWriterStartElementNS: * @writer: the xmlTextWriterPtr * @prefix: namespace prefix or NULL * @name: element local name * @namespaceURI: namespace URI or NULL * * Start an xml element with namespace support. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterStartElementNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI){ int count; int sum; xmlChar *buf; if ((writer == NULL) || (name == NULL) || (*name == '\0')) return -1; buf = 0; if (prefix != 0) { buf = xmlStrdup(prefix); buf = xmlStrcat(buf, BAD_CAST ":"); } buf = xmlStrcat(buf, name); sum = 0; count = xmlTextWriterStartElement(writer, buf); xmlFree(buf); if (count < 0) return -1; sum += count; if (namespaceURI != 0) { buf = xmlStrdup(BAD_CAST "xmlns"); if (prefix != 0) { buf = xmlStrcat(buf, BAD_CAST ":"); buf = xmlStrcat(buf, prefix); } count = xmlTextWriterWriteAttribute(writer, buf, namespaceURI); xmlFree(buf); if (count < 0) return -1; sum += count; } return sum;}/** * 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 */intxmlTextWriterEndElement(xmlTextWriterPtr writer){ int count; int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; if (writer == NULL) return -1; lk = xmlListFront(writer->nodes); if (lk == 0) return -1; p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); if (p == 0) return -1; sum = 0; switch (p->state) { case XML_TEXTWRITER_ATTRIBUTE: count = xmlTextWriterEndAttribute(writer); if (count < 0) return -1; sum += count; /* fallthrough */ case XML_TEXTWRITER_NAME: if (writer->indent) /* next element needs indent */ writer->doindent = 1; count = xmlOutputBufferWriteString(writer->out, "/>"); if (count < 0) return -1; sum += count; break; case XML_TEXTWRITER_TEXT: if ((writer->indent) && (writer->doindent)) { count = xmlTextWriterWriteIndent(writer); sum += count; writer->doindent = 1; } else writer->doindent = 1; count = xmlOutputBufferWriteString(writer->out, "</"); if (count < 0) return -1; sum += count; count = xmlOutputBufferWriteString(writer->out, (const char *) p->name); if (count < 0) return -1; sum += count; count = xmlOutputBufferWriteString(writer->out, ">"); if (count < 0) return -1; sum += count; break; default: return -1; } if (writer->indent) { count = xmlOutputBufferWriteString(writer->out, "\n"); sum += count; } xmlListPopFront(writer->nodes); return sum;}/** * xmlTextWriterFullEndElement: * @writer: the xmlTextWriterPtr * * End the current xml element. Writes an end tag even if the element is empty * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterFullEndElement(xmlTextWriterPtr writer){ int count; int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; if (writer == NULL) return -1; lk = xmlListFront(writer->nodes); if (lk == 0) return -1; p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); if (p == 0) return -1; sum = 0; switch (p->state) { case XML_TEXTWRITER_ATTRIBUTE: count = xmlTextWriterEndAttribute(writer); if (count < 0) return -1; sum += count; /* fallthrough */ case XML_TEXTWRITER_NAME: count = xmlOutputBufferWriteString(writer->out, ">"); if (count < 0) return -1; sum += count; /* fallthrough */ case XML_TEXTWRITER_TEXT: count = xmlOutputBufferWriteString(writer->out, "</"); if (count < 0) return -1; sum += count; count = xmlOutputBufferWriteString(writer->out, (const char *) p->name); if (count < 0) return -1; sum += count; count = xmlOutputBufferWriteString(writer->out, ">"); if (count < 0) return -1; sum += count; break; default: return -1; } xmlListPopFront(writer->nodes); return sum;}/** * xmlTextWriterWriteFormatRaw: * @writer: the xmlTextWriterPtr * @format: format string (see printf) * @...: extra parameters for the format * * Write a formatted raw xml text. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer, const char *format, ...){ int rc; va_list ap; va_start(ap, format); rc = xmlTextWriterWriteVFormatRaw(writer, format, ap); va_end(ap); return rc;}/** * xmlTextWriterWriteVFormatRaw: * @writer: the xmlTextWriterPtr * @format: format string (see printf) * @argptr: pointer to the first member of the variable argument list. * * Write a formatted raw xml text. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer, const char *format, va_list argptr){ int rc; xmlChar *buf; if (writer == NULL) return -1; buf = xmlTextWriterVSprintf(format, argptr); if (buf == 0) return 0; rc = xmlTextWriterWriteRaw(writer, buf); xmlFree(buf); return rc;}/** * xmlTextWriterWriteRawLen: * @writer: the xmlTextWriterPtr * @content: text string * @len: length of the text string * * Write an xml text. * TODO: what about entities and special chars?? * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteRawLen(xmlTextWriterPtr writer, const xmlChar * content, int len){ int count; int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; if (writer == NULL) { xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR, "xmlTextWriterWriteRawLen : invalid writer!\n"); return -1; } if ((content == NULL) || (len < 0)) { xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR, "xmlTextWriterWriteRawLen : invalid content!\n"); return -1; } sum = 0; lk = xmlListFront(writer->nodes); if (lk != 0) { p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); count = xmlTextWriterHandleStateDependencies(writer, p); if (count < 0) return -1; sum += count; } if (writer->indent) writer->doindent = 0; if (content != NULL) { count = xmlOutputBufferWrite(writer->out, len, (const char *) content); if (count < 0) return -1; sum += count; } return sum;}/** * xmlTextWriterWriteRaw: * @writer: the xmlTextWriterPtr * @content: text string * * Write a raw xml text. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content){ return xmlTextWriterWriteRawLen(writer, content, xmlStrlen(content));}/** * xmlTextWriterWriteFormatString: * @writer: the xmlTextWriterPtr * @format: format string (see printf) * @...: extra parameters for the format * * Write a formatted xml text. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteFormatString(xmlTextWriterPtr writer, const char *format, ...){ int rc; va_list ap; if ((writer == NULL) || (format == NULL)) return -1; va_start(ap, format); rc = xmlTextWriterWriteVFormatString(writer, format, ap); va_end(ap); return rc;}/** * xmlTextWriterWriteVFormatString: * @writer: the xmlTextWriterPtr * @format: format string (see printf) * @argptr: pointer to the first member of the variable argument list. * * Write a formatted xml text. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteVFormatString(xmlTextWriterPtr writer, const char *format, va_list argptr){ int rc; xmlChar *buf; if ((writer == NULL) || (format == NULL)) return -1; buf = xmlTextWriterVSprintf(format, argptr); if (buf == 0) return 0; rc = xmlTextWriterWriteString(writer, buf); xmlFree(buf); return rc;}/** * xmlTextWriterWriteString: * @writer: the xmlTextWriterPtr * @content: text string * * Write an xml text. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content){ int count; int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; xmlChar *buf; if ((writer == NULL) || (content == NULL)) return -1; sum = 0; buf = (xmlChar *) content; lk = xmlListFront(writer->nodes); if (lk != 0) { p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); if (p != 0) { switch (p->state) { case XML_TEXTWRITER_NAME: case XML_TEXTWRITER_TEXT:#if 0 buf = NULL; xmlOutputBufferWriteEscape(writer->out, content, NULL);#endif buf = xmlEncodeSpecialChars(NULL, content); break; case XML_TEXTWRITER_ATTRIBUTE: buf = NULL; xmlAttrSerializeTxtContent(writer->out->buffer, NULL, NULL, content); break; default: break; } } } if (buf != NULL) { count = xmlTextWriterWriteRaw(writer, buf); if (count < 0) return -1; sum += count; if (buf != content) /* buf was allocated by us, so free it */ xmlFree(buf); } return sum;}/** * xmlOutputBufferWriteBase64: * @out: the xmlOutputBufferPtr * @data: binary data * @len: the number of bytes to encode * * Write base64 encoded data to an xmlOutputBuffer. * Adapted from John Walker's base64.c (http://www.fourmilab.ch/). * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */static intxmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len, const unsigned char *data){ static unsigned char dtable[64] = {'A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z', 'a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z', '0','1','2','3','4','5','6','7','8','9','+','/'}; int i; int linelen; int count; int sum; if ((out == NULL) || (len < 0) || (data == NULL)) return(-1); linelen = 0; sum = 0; i = 0; while (1) { unsigned char igroup[3]; unsigned char ogroup[4];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -