📄 xmlwriter.c.svn-base
字号:
* @out: the xmlOutputBufferPtr * @data: binary data * @len: the number of bytes to encode * * Write hqx encoded data to an xmlOutputBuffer. * ::todo * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */static intxmlOutputBufferWriteBinHex(xmlOutputBufferPtr out, int len, const unsigned char *data){ int count; int sum; static char hex[] = "0123456789ABCDEF"; int i; if ((out == NULL) || ((data == 0) && (len != 0))) { return -1; } sum = 0; for (i = 0; i < len; i++) { count = xmlOutputBufferWrite(out, 1, (const char *) &hex[data[i] >> 4]); if (count == -1) return -1; sum += count; count = xmlOutputBufferWrite(out, 1, (const char *) &hex[data[i] & 0xF]); if (count == -1) return -1; sum += count; } return sum;}/** * xmlTextWriterWriteBinHex: * @writer: the xmlTextWriterPtr * @data: binary data * @start: the position within the data of the first byte to encode * @len: the number of bytes to encode * * Write a BinHex encoded xml text. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteBinHex(xmlTextWriterPtr writer, const char *data, int start, int len){ int count; int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; if (writer == NULL) return -1; sum = 0; lk = xmlListFront(writer->nodes); if (lk != 0) { p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); if (p != 0) { count = xmlTextWriterHandleStateDependencies(writer, p); if (count < 0) return -1; sum += count; } } if (writer->indent) writer->doindent = 0; count = xmlOutputBufferWriteBinHex(writer->out, len, (unsigned char *) data + start); if (count < 0) return -1; sum += count; return sum;}/** * xmlTextWriterStartAttribute: * @writer: the xmlTextWriterPtr * @name: element name * * Start an xml attribute. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterStartAttribute(xmlTextWriterPtr writer, const xmlChar * name){ int count; int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; if ((writer == NULL) || (name == NULL) || (*name == '\0')) return -1; sum = 0; lk = xmlListFront(writer->nodes); if (lk == 0) return -1; p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); if (p == 0) return -1; 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; count = xmlOutputBufferWriteString(writer->out, (const char *) name); if (count < 0) return -1; sum += count; count = xmlOutputBufferWriteString(writer->out, "="); if (count < 0) return -1; sum += count; count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar); if (count < 0) return -1; sum += count; p->state = XML_TEXTWRITER_ATTRIBUTE; break; default: return -1; } return sum;}/** * xmlTextWriterStartAttributeNS: * @writer: the xmlTextWriterPtr * @prefix: namespace prefix or NULL * @name: element local name * @namespaceURI: namespace URI or NULL * * Start an xml attribute with namespace support. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterStartAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI){ int count; int sum; xmlChar *buf; xmlTextWriterNsStackEntry *p; 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 = xmlTextWriterStartAttribute(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); } p = (xmlTextWriterNsStackEntry *) xmlMalloc(sizeof(xmlTextWriterNsStackEntry)); if (p == 0) { xmlGenericError(xmlGenericErrorContext, "xmlTextWriterStartAttributeNS : out of memory!\n"); return -1; } p->prefix = buf; p->uri = xmlStrdup(namespaceURI); if (p->uri == 0) { xmlGenericError(xmlGenericErrorContext, "xmlTextWriterStartAttributeNS : out of memory!\n"); xmlFree(p); return -1; } p->elem = xmlListFront(writer->nodes); xmlListPushFront(writer->nsstack, p); } return sum;}/** * xmlTextWriterEndAttribute: * @writer: the xmlTextWriterPtr * * End the current xml element. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterEndAttribute(xmlTextWriterPtr writer){ int count; int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; xmlTextWriterNsStackEntry *np; if (writer == NULL) return -1; lk = xmlListFront(writer->nodes); if (lk == 0) { xmlListDelete(writer->nsstack); return -1; } p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); if (p == 0) { xmlListDelete(writer->nsstack); return -1; } sum = 0; switch (p->state) { case XML_TEXTWRITER_ATTRIBUTE: p->state = XML_TEXTWRITER_NAME; count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar); if (count < 0) { xmlListDelete(writer->nsstack); return -1; } sum += count; while (!xmlListEmpty(writer->nsstack)) { lk = xmlListFront(writer->nsstack); np = (xmlTextWriterNsStackEntry *) xmlLinkGetData(lk); if (np != 0) { count = xmlTextWriterWriteAttribute(writer, np->prefix, np->uri); if (count < 0) { xmlListDelete(writer->nsstack); return -1; } sum += count; } xmlListPopFront(writer->nsstack); } break; default: xmlListClear(writer->nsstack); return -1; } return sum;}/** * xmlTextWriterWriteFormatAttribute: * @writer: the xmlTextWriterPtr * @name: attribute name * @format: format string (see printf) * @...: extra parameters for the format * * Write a formatted xml attribute. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer, const xmlChar * name, const char *format, ...){ int rc; va_list ap; va_start(ap, format); rc = xmlTextWriterWriteVFormatAttribute(writer, name, format, ap); va_end(ap); return rc;}/** * xmlTextWriterWriteVFormatAttribute: * @writer: the xmlTextWriterPtr * @name: attribute name * @format: format string (see printf) * @argptr: pointer to the first member of the variable argument list. * * Write a formatted xml attribute. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer, const xmlChar * name, 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 = xmlTextWriterWriteAttribute(writer, name, buf); xmlFree(buf); return rc;}/** * xmlTextWriterWriteAttribute: * @writer: the xmlTextWriterPtr * @name: attribute name * @content: attribute content * * Write an xml attribute. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteAttribute(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * content){ int count; int sum; sum = 0; count = xmlTextWriterStartAttribute(writer, name); if (count < 0) return -1; sum += count; count = xmlTextWriterWriteString(writer, content); if (count < 0) return -1; sum += count; count = xmlTextWriterEndAttribute(writer); if (count < 0) return -1; sum += count; return sum;}/** * xmlTextWriterWriteFormatAttributeNS: * @writer: the xmlTextWriterPtr * @prefix: namespace prefix * @name: attribute local name * @namespaceURI: namespace URI * @format: format string (see printf) * @...: extra parameters for the format * * Write a formatted xml attribute.with namespace support * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const char *format, ...){ int rc; va_list ap; va_start(ap, format); rc = xmlTextWriterWriteVFormatAttributeNS(writer, prefix, name, namespaceURI, format, ap); va_end(ap); return rc;}/** * xmlTextWriterWriteVFormatAttributeNS: * @writer: the xmlTextWriterPtr * @prefix: namespace prefix * @name: attribute local name * @namespaceURI: namespace URI * @format: format string (see printf) * @argptr: pointer to the first member of the variable argument list. * * Write a formatted xml attribute.with namespace support * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, 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 = xmlTextWriterWriteAttributeNS(writer, prefix, name, namespaceURI, buf); xmlFree(buf); return rc;}/** * xmlTextWriterWriteAttributeNS: * @writer: the xmlTextWriterPtr * @prefix: namespace prefix * @name: attribute local name * @namespaceURI: namespace URI * @content: attribute content * * Write an xml attribute. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */intxmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const xmlChar * content){ int count; int sum; xmlChar *buf; if ((writer == NULL) || (name == NULL) || (*name == '\0')) return -1; buf = 0; if (prefix != NULL) { buf = xmlStrdup(prefix); buf = xmlStrcat(buf, BAD_CAST ":"); } buf = xmlStrcat(buf, name); sum = 0; count = xmlTextWriterWriteAttribute(writer, buf, content); xmlFree(buf); if (count < 0) return -1; sum += count; if (namespaceURI != NULL) { buf = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -