Determines whether an OpenXML file appears to be good (not corrupted).
343257
def is_openxml_good(filename: str) -> bool:
    
    try:
        log.debug("Trying: {}", filename)
        with ZipFile(filename, 'r') as zip_ref:
            namelist = zip_ref.namelist()  # type: List[str]
            # log.critical("\n{}", pformat(namelist))
            # -----------------------------------------------------------------
            # Contains key files?
            # -----------------------------------------------------------------
            for mandatory_filename in MANDATORY_FILENAMES:
                if mandatory_filename not in namelist:
                    log.debug("Bad [missing {!r}]: {}",
                              mandatory_filename, filename)
                    return False

            infolist = zip_ref.infolist()  # type: List[ZipInfo]
            contains_docx = False
            contains_pptx = False
            contains_xlsx = False
            for info in infolist:
                # -------------------------------------------------------------
                # Sensible date check?
                # ... NO: lots of perfectly good files have this date/time.
                # -------------------------------------------------------------
                # if info.date_time == NULL_DATE_TIME:
                #     log.debug("{!r}: {!r}", info.filename, info.date_time)

                # -------------------------------------------------------------
                # Only one kind of contents?
                # ... YES, I think so. This has 100% reliability on my
                # stash of 34 PPTX, 223 DOCX, 85 XLSX, and labelled none as bad
                # from an HFC collection of 1866 such files. There are lots of
                # files emerging from Scalpel (plus my find_recovered_openxml
                # zip-fixing tool) that fail this test, though.
                # -------------------------------------------------------------
                if (not contains_docx and
                        DOCX_CONTENTS_REGEX.search(info.filename)):
                    contains_docx = True
                if (not contains_pptx and
                        PPTX_CONTENTS_REGEX.search(info.filename)):
                    contains_pptx = True
                if (not contains_xlsx and
                        XLSX_CONTENTS_REGEX.search(info.filename)):
                    contains_xlsx = True
                if sum([contains_docx, contains_pptx, contains_xlsx]) > 1:
                    log.debug("Bad [>1 of DOCX, PPTX, XLSX content]: {}",
                              filename)
                    return False

            return True
    except (BadZipFile, OSError) as e:
        # ---------------------------------------------------------------------
        # Duff file. Easy!
        # ---------------------------------------------------------------------
        log.debug("Bad [BadZipFile or OSError]: {!r}; error was {!r}",
                  filename, e)
        return False
98672
public boolean validateAgainstXsdFile(String xsdFileName) {
        String xsdContent = new FileFixture().textIn(xsdFileName);
        return new XMLValidator().validateAgainst(content, xsdContent);
    }
1170394
def isSupportedContent(cls, fileContent):
        """"""
        magic = bytearray(fileContent)[:4]
        return magic == p('>I', 0xfeedface) or magic == p('>I', 0xfeedfacf) or magic == p('<I', 0xfeedface) or magic == p('<I', 0xfeedfacf)
1059521
private void verifyXopResponse(XopBean xopOriginal, XopBean xopResponse) {
        if (!Arrays.equals(xopResponse.getBytes(), xopOriginal.getBytes())) {
            throw new RuntimeException("Received XOP attachment is corrupted");
        }
        System.out.println();
        System.out.println("XOP attachment has been successfully received");
    }
1303670
def _is_valid_file(self, path):
        """"""
        return isinstance(path, basestring) and os.path.isfile(path)
1070801
private boolean isValid() {

        return m_typeID.isValid()
            && m_typeShortName.isValid()
            && m_parentFormatter.isValid()
            && m_parentSchema.isValid()
            && m_bundle.isValid()
            && m_config.isValid()
            && m_typeDescription.isValid()
            && m_typeName.isValid()
            && m_typeXPathName.isValid();
    }
1366258
public boolean isXmlDeclaration() {
        String data = getData();
        return (data.length() > 1 && (data.startsWith("!") || data.startsWith("?")));
    }
559080
public static function isValidXml($xml, $doc = null)
    {
        if ($doc == null) {
            $doc = new DOMDocument("1.0", "ISO-8859-1");
        }

        // tries to load the document and gets the errors
        $useInternalErrors = libxml_use_internal_errors(true);
        $doc->loadXML($xml);
        $errors = libxml_get_errors();
        libxml_use_internal_errors($useInternalErrors);

        return count($errors) == 0;
    }
1121820
def is_xml(text):
    
    # BOM_UTF8 is an UTF-8 byte order mark which may precede the XML from an Exchange server
    bom_len = len(BOM_UTF8)
    if text[:bom_len] == BOM_UTF8:
        return text[bom_len:bom_len + 5] == b'<?xml'
    return text[:5] == b'<?xml'
8403
def is_xml(origin, filepath, fileobj, *args, **kwargs):
    
    # pylint: disable=unused-argument
    if fileobj is not None:
        loc = fileobj.tell()
        fileobj.seek(0)
        try:
            sig = fileobj.read(5).lower()
            return sig == XML_SIGNATURE
        finally:
            fileobj.seek(loc)
    elif filepath is not None:
        return filepath.endswith(('.xml', '.xml.gz'))
1341935
public static void assertXMLNotEqual(Reader control, Reader test)
        throws SAXException, IOException {
        assertXMLNotEqual(null, control, test);
    }
544176
private static boolean isAppXml(final String mime) {
        return mime != null
                && (mime.equals("application/xml") || mime.equals("application/xml-dtd") || mime.equals("application/xml-external-parsed-entity") || mime
                        .startsWith("application/") && mime.endsWith("+xml"));
    }
31875
private static boolean isValidFileSystemUri(URI uri) {
    // would like to just check null, but fragment appears to be the empty string when not present
    return isNullOrEmpty(uri.getPath())
        && isNullOrEmpty(uri.getQuery())
        && isNullOrEmpty(uri.getFragment());
  }
948662
public static boolean isValidXMLName(String s) {

		// Catch the empty string or null.
		if (s == null || "".equals(s)) {
			return false;
		}

		// Since the string isn't empty, check that the first character is a
		// valid starting character.
		if (!isXMLNameStart(s.codePointAt(0))) {
			return false;
		}

		// Loop through the string by UNICODE codepoints. This is NOT equivalent
		// to looping through the characters because some UNICODE codepoints can
		// occupy more than one character.
		int length = s.length();
		int index = 1;
		while (index < length) {
			int codePoint = s.codePointAt(index);
			if (!isXMLNamePart(codePoint)) {
				return false;
			}
			index += Character.charCount(codePoint);
		}

		// Names that begin with "xml" with letters in any case are reserved by
		// the XML specification.
		if (s.toLowerCase().startsWith("xml")) {
			return false;
		}

		// If we get here then all of the characters have been checked and are
		// valid. Unfortunately the usual case takes the longest to verify.
		return true;
	}
1242395
def str_is_well_formed(xml_str):
    
    try:
        str_to_etree(xml_str)
    except xml.etree.ElementTree.ParseError:
        return False
    else:
        return True
709322
public void isWelformed(String xml) {
        StringReader reader = new StringReader(xml);
        XMLStreamReader r = null;
        try {
            r = XML_INPUT_FACTORY.createXMLStreamReader(reader);
            while (r.hasNext()) {
                r.next();
            }
        } catch (XMLStreamException e) {
            throw new RuntimeException(e);
        } finally {
            if (r != null) {
                try {
                    r.close();
                } catch (Exception e) {
                    // should not happen
                }
            }
            reader.close();
        }
    }
298544
public boolean checkWelformed(String xml)  {
        boolean result;
        try {
            isWelformed(xml);
            result = true;
        } catch (RuntimeException e) {
            result = false;
        }
        return result;
    }