XMLPARSEAPI(int)
XML_GetIdAttributeIndex(XML_Parser parser);
-/* Parses some input. Returns 0 if a fatal error is detected. The
- last call to XML_Parse must have isFinal true; len may be zero for
- this call (or any other).
-*/
-XMLPARSEAPI(int)
+/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
+ detected. The last call to XML_Parse must have isFinal true; len
+ may be zero for this call (or any other).
+
+ The XML_Status enum gives the possible return values for the
+ XML_Parse and XML_ParseBuffer functions. Though the return values
+ for these functions has always been described as a Boolean value,
+ the implementation, at least for the 1.95.x series, has always
+ returned exactly one of these values. The preprocessor #defines
+ are included so this stanza can be added to code that still needs
+ to support older versions of Expat 1.95.x:
+
+ #ifndef XML_STATUS_OK
+ #define XML_STATUS_OK 1
+ #define XML_STATUS_ERROR 0
+ #endif
+
+ Otherwise, the #define hackery is quite ugly and would have been dropped.
+*/
+enum XML_Status {
+ XML_STATUS_ERROR = 0,
+#define XML_STATUS_ERROR XML_STATUS_ERROR
+ XML_STATUS_OK = 1
+#define XML_STATUS_OK XML_STATUS_OK
+};
+
+XMLPARSEAPI(enum XML_Status)
XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
XMLPARSEAPI(void *)
XML_GetBuffer(XML_Parser parser, int len);
-XMLPARSEAPI(int)
+XMLPARSEAPI(enum XML_Status)
XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
/* Creates an XML_Parser object that can parse an external general
char text[] = "<doc>\0</doc>";
/* test that a NUL byte (in US-ASCII data) is an error */
- if (XML_Parse(parser, text, sizeof(text) - 1, 1))
+ if (XML_Parse(parser, text, sizeof(text) - 1, 1) == XML_STATUS_OK)
fail("Parser did not report error on NUL-byte.");
if (XML_GetErrorCode(parser) != XML_ERROR_INVALID_TOKEN)
xml_failure(parser);
char *text = "<doc>�</doc>";
/* test that a NUL byte (in US-ASCII data) is an error */
- if (XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK)
fail("Parser did not report error on NUL-byte.");
if (XML_GetErrorCode(parser) != XML_ERROR_BAD_CHAR_REF)
xml_failure(parser);
/* This test is really just making sure we don't core on a UTF-8 BOM. */
char *text = "\357\273\277<e/>";
- if (!XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
xml_failure(parser);
}
END_TEST
{
char text[] = "\376\377\0<\0e\0/\0>";
- if (!XML_Parse(parser, text, sizeof(text) - 1, 1))
+ if (XML_Parse(parser, text, sizeof(text) - 1, 1) == XML_STATUS_ERROR)
xml_failure(parser);
}
END_TEST
{
char text[] = "\377\376<\0e\0/\0>\0";
- if (!XML_Parse(parser, text, sizeof(text) - 1, 1))
+ if (XML_Parse(parser, text, sizeof(text) - 1, 1) == XML_STATUS_ERROR)
xml_failure(parser);
}
END_TEST
CharData_Init(&storage);
XML_SetUserData(parser, &storage);
XML_SetCharacterDataHandler(parser, accumulate_characters);
- if (!XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
xml_failure(parser);
CharData_CheckXMLChars(&storage, expected);
}
CharData_Init(&storage);
XML_SetUserData(parser, &storage);
XML_SetStartElementHandler(parser, accumulate_attribute);
- if (!XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
xml_failure(parser);
CharData_CheckXMLChars(&storage, expected);
}
for (i = 128; i <= 255; ++i) {
sprintf(text, "<e>%ccd</e>", i);
- if (XML_Parse(parser, text, strlen(text), 1)) {
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK) {
sprintf(text,
"expected token error for '%c' (ordinal %d) in UTF-8 text",
i, i);
"\000<\000d\000o\000c\000 \000a\000=\000'\0001\0002\0003\000'"
"\000>\000s\000o\000m\000e\000 \000t\000e\000x\000t\000<\000/"
"\000d\000o\000c\000>";
- if (!XML_Parse(parser, text, sizeof(text) - 1, 1))
+ if (XML_Parse(parser, text, sizeof(text) - 1, 1) == XML_STATUS_ERROR)
xml_failure(parser);
}
END_TEST
" <e/>\n"
"</e>";
int lineno;
- if (!XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
xml_failure(parser);
lineno = XML_GetCurrentLineNumber(parser);
if (lineno != 3) {
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+"
"</e>";
- if (!XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
xml_failure(parser);
}
END_TEST
CharData_Init(&storage);
XML_SetUserData(parser, &storage);
XML_SetEndElementHandler(parser, end_element_event_handler);
- if (!XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
xml_failure(parser);
CharData_CheckString(&storage, expected);
}
XML_SetStartElementHandler(parser,
check_attr_contains_normalized_whitespace);
- if (!XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
xml_failure(parser);
}
END_TEST
"<?xml version='1.0'?>\n"
"<a>&eee;</a>";
- if (!XML_Parse(parser, text, strlen(text), 1)) {
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) {
if (XML_GetErrorCode(parser) != XML_ERROR_MISPLACED_XML_PI)
xml_failure(parser);
}
"<test a='&foo;'/>";
XML_SetUnknownEncodingHandler(parser, UnknownEncodingHandler, NULL);
- if (!XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
xml_failure(parser);
}
END_TEST
XML_SetReturnNSTriplet(parser, 1);
XML_SetUserData(parser, elemstr);
XML_SetElementHandler(parser, triplet_start_checker, triplet_end_checker);
- if (!XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
xml_failure(parser);
}
END_TEST
XML_SetUserData(parser, &storage);
XML_SetElementHandler(parser,
overwrite_start_checker, overwrite_end_checker);
- if (!XML_Parse(parser, text, strlen(text), 1))
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
xml_failure(parser);
CharData_CheckString(&storage, result);
}