| 6142 | */ |
| 6143 | |
| 6144 | int |
| 6145 | xmlValidateRoot(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { |
| 6146 | xmlNodePtr root; |
| 6147 | int ret; |
| 6148 | |
| 6149 | if (doc == NULL) return(0); |
| 6150 | |
| 6151 | root = xmlDocGetRootElement(doc); |
| 6152 | if ((root == NULL) || (root->name == NULL)) { |
| 6153 | xmlErrValid(ctxt, XML_DTD_NO_ROOT, |
| 6154 | "no root element\n", NULL); |
| 6155 | return(0); |
| 6156 | } |
| 6157 | |
| 6158 | /* |
| 6159 | * When doing post validation against a separate DTD, those may |
| 6160 | * no internal subset has been generated |
| 6161 | */ |
| 6162 | if ((doc->intSubset != NULL) && |
| 6163 | (doc->intSubset->name != NULL)) { |
| 6164 | /* |
| 6165 | * Check first the document root against the NQName |
| 6166 | */ |
| 6167 | if (!xmlStrEqual(doc->intSubset->name, root->name)) { |
| 6168 | if ((root->ns != NULL) && (root->ns->prefix != NULL)) { |
| 6169 | xmlChar fn[50]; |
| 6170 | xmlChar *fullname; |
| 6171 | |
| 6172 | fullname = xmlBuildQName(root->name, root->ns->prefix, fn, 50); |
| 6173 | if (fullname == NULL) { |
| 6174 | xmlVErrMemory(ctxt); |
| 6175 | return(0); |
| 6176 | } |
| 6177 | ret = xmlStrEqual(doc->intSubset->name, fullname); |
| 6178 | if ((fullname != fn) && (fullname != root->name)) |
| 6179 | xmlFree(fullname); |
| 6180 | if (ret == 1) |
| 6181 | goto name_ok; |
| 6182 | } |
| 6183 | if ((xmlStrEqual(doc->intSubset->name, BAD_CAST "HTML")) && |
| 6184 | (xmlStrEqual(root->name, BAD_CAST "html"))) |
| 6185 | goto name_ok; |
| 6186 | xmlErrValidNode(ctxt, root, XML_DTD_ROOT_NAME, |
| 6187 | "root and DTD name do not match '%s' and '%s'\n", |
| 6188 | root->name, doc->intSubset->name, NULL); |
| 6189 | return(0); |
| 6190 | } |
| 6191 | } |
| 6192 | name_ok: |
| 6193 | return(1); |
| 6194 | } |
| 6195 | |
| 6196 | |
| 6197 | /** |
no test coverage detected