def validate_doc(schema_names,  <EOL>doc,           <EOL>loader,        <EOL>strict,        <EOL>strict_foreign_properties=False  <EOL>):<EOL>
has_root = False<EOL>for root in schema_names.names.values():<EOL><INDENT>if ((hasattr(root, '<STR_LIT>') and root.get_prop(u"<STR_LIT>")) or (<EOL>u"<STR_LIT>" in root.props)):<EOL><INDENT>has_root = True<EOL>break<EOL><DEDENT><DEDENT>if not has_root:<EOL><INDENT>raise validate.ValidationException(<EOL>"<STR_LIT>")<EOL><DEDENT>if isinstance(doc, MutableSequence):<EOL><INDENT>vdoc = doc<EOL><DEDENT>elif isinstance(doc, CommentedMap):<EOL><INDENT>vdoc = CommentedSeq([doc])<EOL>vdoc.lc.add_kv_line_col(<NUM_LIT:0>, [doc.lc.line, doc.lc.col])<EOL>vdoc.lc.filename = doc.lc.filename<EOL><DEDENT>else:<EOL><INDENT>raise validate.ValidationException("<STR_LIT>")<EOL><DEDENT>roots = []<EOL>for root in schema_names.names.values():<EOL><INDENT>if ((hasattr(root, "<STR_LIT>") and root.get_prop(u"<STR_LIT>")) or (<EOL>root.props.get(u"<STR_LIT>"))):<EOL><INDENT>roots.append(root)<EOL><DEDENT><DEDENT>anyerrors = []<EOL>for pos, item in enumerate(vdoc):<EOL><INDENT>sourceline = SourceLine(vdoc, pos, Text)<EOL>success = False<EOL>for root in roots:<EOL><INDENT>success = validate.validate_ex(<EOL>root, item, loader.identifiers, strict,<EOL>foreign_properties=loader.foreign_properties,<EOL>raise_ex=False, skip_foreign_properties=loader.skip_schemas,<EOL>strict_foreign_properties=strict_foreign_properties)<EOL>if success:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if not success:<EOL><INDENT>errors = []  <EOL>for root in roots:<EOL><INDENT>if hasattr(root, "<STR_LIT>"):<EOL><INDENT>name = root.get_prop(u"<STR_LIT:name>")<EOL><DEDENT>elif hasattr(root, "<STR_LIT:name>"):<EOL><INDENT>name = root.name<EOL><DEDENT>try:<EOL><INDENT>validate.validate_ex(<EOL>root, item, loader.identifiers, strict,<EOL>foreign_properties=loader.foreign_properties,<EOL>raise_ex=True, skip_foreign_properties=loader.skip_schemas,<EOL>strict_foreign_properties=strict_foreign_properties)<EOL><DEDENT>except validate.ClassValidationException as exc:<EOL><INDENT>errors = [sourceline.makeError(u"<STR_LIT>" % (<EOL>name, validate.indent(str(exc), nolead=False)))]<EOL>break<EOL><DEDENT>except validate.ValidationException as exc:<EOL><INDENT>errors.append(sourceline.makeError(u"<STR_LIT>" % (<EOL>name, validate.indent(str(exc), nolead=False))))<EOL><DEDENT><DEDENT>objerr = sourceline.makeError(u"<STR_LIT>")<EOL>for ident in loader.identifiers:<EOL><INDENT>if ident in item:<EOL><INDENT>objerr = sourceline.makeError(<EOL>u"<STR_LIT>"<EOL>% (relname(item[ident])))<EOL>break<EOL><DEDENT><DEDENT>anyerrors.append(u"<STR_LIT>" %<EOL>(objerr, validate.indent(bullets(errors, "<STR_LIT>"))))<EOL><DEDENT><DEDENT>if anyerrors:<EOL><INDENT>raise validate.ValidationException(<EOL>strip_dup_lineno(bullets(anyerrors, "<STR_LIT>")))<EOL><DEDENT>
Validate a document using the provided schema.