| 4747 | */ |
| 4748 | |
| 4749 | int |
| 4750 | htmlParseDocument(htmlParserCtxtPtr ctxt) { |
| 4751 | xmlDtdPtr dtd; |
| 4752 | |
| 4753 | if ((ctxt == NULL) || (ctxt->input == NULL)) |
| 4754 | return(-1); |
| 4755 | |
| 4756 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) { |
| 4757 | ctxt->sax->setDocumentLocator(ctxt->userData, |
| 4758 | (xmlSAXLocator *) &xmlDefaultSAXLocator); |
| 4759 | } |
| 4760 | |
| 4761 | xmlDetectEncoding(ctxt); |
| 4762 | |
| 4763 | /* |
| 4764 | * This is wrong but matches long-standing behavior. In most cases, |
| 4765 | * a document starting with an XML declaration will specify UTF-8. |
| 4766 | */ |
| 4767 | if (((ctxt->input->flags & XML_INPUT_HAS_ENCODING) == 0) && |
| 4768 | (xmlStrncmp(ctxt->input->cur, BAD_CAST "<?xm", 4) == 0)) |
| 4769 | xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_UTF8); |
| 4770 | |
| 4771 | /* |
| 4772 | * Wipe out everything which is before the first '<' |
| 4773 | */ |
| 4774 | SKIP_BLANKS; |
| 4775 | if (CUR == 0) { |
| 4776 | htmlParseErr(ctxt, XML_ERR_DOCUMENT_EMPTY, |
| 4777 | "Document is empty\n", NULL, NULL); |
| 4778 | } |
| 4779 | |
| 4780 | if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX)) |
| 4781 | ctxt->sax->startDocument(ctxt->userData); |
| 4782 | |
| 4783 | /* |
| 4784 | * Parse possible comments and PIs before any content |
| 4785 | */ |
| 4786 | while (((CUR == '<') && (NXT(1) == '!') && |
| 4787 | (NXT(2) == '-') && (NXT(3) == '-')) || |
| 4788 | ((CUR == '<') && (NXT(1) == '?'))) { |
| 4789 | htmlParseComment(ctxt); |
| 4790 | htmlParsePI(ctxt); |
| 4791 | SKIP_BLANKS; |
| 4792 | } |
| 4793 | |
| 4794 | |
| 4795 | /* |
| 4796 | * Then possibly doc type declaration(s) and more Misc |
| 4797 | * (doctypedecl Misc*)? |
| 4798 | */ |
| 4799 | if ((CUR == '<') && (NXT(1) == '!') && |
| 4800 | (UPP(2) == 'D') && (UPP(3) == 'O') && |
| 4801 | (UPP(4) == 'C') && (UPP(5) == 'T') && |
| 4802 | (UPP(6) == 'Y') && (UPP(7) == 'P') && |
| 4803 | (UPP(8) == 'E')) { |
| 4804 | htmlParseDocTypeDecl(ctxt); |
| 4805 | } |
| 4806 | SKIP_BLANKS; |
no test coverage detected