MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlTextWriterStartDocument

Function xmlTextWriterStartDocument

ThirdParty/libxml2/vtklibxml2/xmlwriter.c:507–616  ·  view source on GitHub ↗

* xmlTextWriterStartDocument: * @writer: the xmlTextWriterPtr * @version: the xml version ("1.0") or NULL for default ("1.0") * @encoding: the encoding or NULL for default * @standalone: "yes" or "no" or NULL for default * * Start a new xml document * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */

Source from the content-addressed store, hash-verified

505 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
506 */
507int
508xmlTextWriterStartDocument(xmlTextWriterPtr writer, const char *version,
509 const char *encoding, const char *standalone)
510{
511 int count;
512 int sum;
513 xmlLinkPtr lk;
514 xmlCharEncodingHandlerPtr encoder;
515
516 if ((writer == NULL) || (writer->out == NULL)) {
517 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
518 "xmlTextWriterStartDocument : invalid writer!\n");
519 return -1;
520 }
521
522 lk = xmlListFront(writer->nodes);
523 if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
524 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
525 "xmlTextWriterStartDocument : not allowed in this context!\n");
526 return -1;
527 }
528
529 encoder = NULL;
530 if (encoding != NULL) {
531 encoder = xmlFindCharEncodingHandler(encoding);
532 if (encoder == NULL) {
533 xmlWriterErrMsg(writer, XML_ERR_UNSUPPORTED_ENCODING,
534 "xmlTextWriterStartDocument : unsupported encoding\n");
535 return -1;
536 }
537 }
538
539 writer->out->encoder = encoder;
540 if (encoder != NULL) {
541 if (writer->out->conv == NULL) {
542 writer->out->conv = xmlBufCreateSize(4000);
543 }
544 xmlCharEncOutput(writer->out, 1);
545 if ((writer->doc != NULL) && (writer->doc->encoding == NULL))
546 writer->doc->encoding = xmlStrdup((xmlChar *)writer->out->encoder->name);
547 } else
548 writer->out->conv = NULL;
549
550 sum = 0;
551 count = xmlOutputBufferWriteString(writer->out, "<?xml version=");
552 if (count < 0)
553 return -1;
554 sum += count;
555 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
556 if (count < 0)
557 return -1;
558 sum += count;
559 if (version != 0)
560 count = xmlOutputBufferWriteString(writer->out, version);
561 else
562 count = xmlOutputBufferWriteString(writer->out, "1.0");
563 if (count < 0)
564 return -1;

Callers

nothing calls this directly

Calls 9

xmlWriterErrMsgFunction · 0.85
xmlListFrontFunction · 0.85
xmlLinkGetDataFunction · 0.85
xmlBufCreateSizeFunction · 0.85
xmlCharEncOutputFunction · 0.85
xmlStrdupFunction · 0.85
xmlOutputBufferWriteFunction · 0.85

Tested by

no test coverage detected