598 char q, e, *d, *temp, **attr, **a = NULL;
604 return ezxml_err(root, NULL,
"root tag missing");
606 root->
e = (root->
s = s) + len;
611 while (*s && *s !=
'<')
614 return ezxml_err(root, s,
"root tag missing");
620 if (isalpha(*s) || *s ==
'_' || *s ==
':' || *s <
'\0') {
622 return ezxml_err(root, d,
"markup outside of root element");
625 while (isspace(*s)) {
631 if (*s && *s !=
'/' && *s !=
'>') {
634 for (i = 0; a && strcmp(a[0], d); i++) {
639 for (l = 0; *s && *s !=
'/' && *s !=
'>'; l += 2) {
641 (
char**)realloc(attr, (l + 4) *
sizeof(
char *)) :
642 (char**)malloc(4 * sizeof(char *));
644 (l) ? (
char*)realloc(attr[l + 1], (l / 2) + 2) : (char*)malloc(2);
645 strcpy(attr[l + 3] + (l / 2),
" ");
651 if (*s ==
'=' || isspace(*s)) {
655 q = *(s += strspn(s,
EZXML_WS "="));
656 if (q ==
'"' || q ==
'\'') {
658 while (*s && *s != q)
664 return ezxml_err(root, d,
"missing %c", q);
667 for (j = 1; a && a[j] && strcmp(a[j], attr[l]); j += 3)
670 root->
ent, (a && a[j]) ? *a[j + 2] :
' ');
671 if (attr[l + 1] < d || attr[l + 1] > s)
675 while (isspace(*s)) {
684 if ((*s && *s !=
'>') || (!*s && e !=
'>')) {
691 }
else if ((q = *s) ==
'>' || (!*s && e ==
'>')) {
700 }
else if (*s ==
'/') {
701 s += strcspn(d = s + 1,
EZXML_WS ">") + 1;
709 if (isspace(*s = q)) {
714 }
else if (!strncmp(s,
"!--", 3)) {
716 s = strstr(s + 3,
"--");
717 if (!s || (*(s += 2) !=
'>' && *s) || (!*s && e !=
'>'))
718 return ezxml_err(root, d,
"unclosed <!--");
719 while (temp != s && *temp !=
'\0') {
725 }
else if (!strncmp(s,
"![CDATA[", 8)) {
727 s = strstr(s,
"]]>");
731 return ezxml_err(root, d,
"unclosed <![CDATA[");
732 }
else if (!strncmp(s,
"!DOCTYPE", 8)) {
735 && ((!l && *s !=
'>')
742 l = (*s ==
'[') ? 1 : l)
743 s += strcspn(s + 1,
"[]>") + 1;
745 return ezxml_err(root, d,
"unclosed <!DOCTYPE");
746 d = (l) ? strchr(d,
'[') + 1 : d;
749 }
else if (*s ==
'?') {
752 }
while (s && *(++s) && *s !=
'>');
753 if (!s || (!*s && e !=
'>'))
754 return ezxml_err(root, d,
"unclosed <?");
758 return ezxml_err(root, d,
"unexpected <");
764 if (*s && *s !=
'<') {
765 while (*s && *s !=
'<') {
782 return ezxml_err(root, d,
"root tag missing");
struct ezxml_root * ezxml_root_t
static void ezxml_char_content(ezxml_root_t root, char *s, size_t len, char t)
static void ezxml_open_tag(ezxml_root_t root, int line, char *name, char **attr)
static ezxml_t ezxml_close_tag(ezxml_root_t root, char *name, char *s)
ezxml_t ezxml_new(char *name)
static void ezxml_free_attr(char **attr)
static char * ezxml_decode(char *s, char **ent, char t)
static char * ezxml_str2utf8(char **s, size_t *len)
static short ezxml_internal_dtd(ezxml_root_t root, char *s, size_t len)
static void ezxml_proc_inst(ezxml_root_t root, char *s, size_t len)
static ezxml_t ezxml_err(ezxml_root_t root, char *s, const char *err,...)