docs: private void validateResource(List<ValidationMessage> errors, WrapperElement resource, WrapperElement element, StructureDefinition profile, IdStatus idstatus, NodeStack stack) throws FHIRException {
      if (stack == null)
        stack = new NodeStack(element.isXml());
  		if (resource == null)
  			resource = element;
  
      // getting going - either we got a profile, or not.
      boolean ok = true;
      if (element.isXml()) {
        ok = rule(errors, IssueType.INVALID, element.line(), element.col(), "/", element.getNamespace().equals(FormatUtilities.FHIR_NS),
            "Namespace mismatch - expected '" + FormatUtilities.FHIR_NS + "', found '" + element.getNamespace() + "'");
      }
      if (ok) {
        String resourceName = element.getResourceType();
        if (profile == null) {
          profile = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + resourceName);
          ok = rule(errors, IssueType.INVALID, element.line(), element.col(), stack.addToLiteralPath(resourceName), profile != null, "No profile found for resource type '" + resourceName + "'");
        } else {
          String type = profile.hasConstrainedType() ? profile.getConstrainedType() : profile.getName();
          // special case: we have a bundle, and the profile is not for a bundle. We'll try the first entry instead
          if (!type.equals(resourceName) && resourceName.equals("Bundle")) {
            WrapperElement first = getFirstEntry(element);
            if (first != null && first.getResourceType().equals(type)) {
              element = first;
              resourceName = element.getResourceType();
  						idstatus = IdStatus.OPTIONAL; // why?
            }
          }
          ok = rule(errors, IssueType.INVALID, -1, -1, stack.addToLiteralPath(resourceName), type.equals(resourceName),
              "Specified profile type was '" + profile.getConstrainedType() + "', but resource type was '" + resourceName + "'");
        }
      }
  
      if (ok) {
        stack = stack.push(element, -1, profile.getSnapshot().getElement().get(0), profile.getSnapshot().getElement().get(0));
  			if (idstatus == IdStatus.REQUIRED && (element.getNamedChild("id") == null))
  				rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), false, "Resource requires an id, but none is present");
  			else if (idstatus == IdStatus.PROHIBITED && (element.getNamedChild("id") != null))
  				rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), false, "Resource has an id, but none is allowed");
  			start(errors, resource, element, profile, stack); // root is both definition and type
      }
    }