MCPcopy Create free account
hub / github.com/afkT/DevUtils / xmlTag

Method xmlTag

lib/DevApp/src/main/java/dev/utils/LogPrintUtils.java:448–484  ·  view source on GitHub ↗

将 XML 格式化缩进后打印为 DEBUG 日志 内容为空时打印 ERROR 提示;解析失败时打印异常与原始 XML。 @param tag 日志 TAG @param xml XML 字符串

(
            final String tag,
            final String xml
    )

Source from the content-addressed store, hash-verified

446 * @param xml XML 字符串
447 */
448 public static void xmlTag(
449 final String tag,
450 final String xml
451 ) {
452 if (JUDGE_PRINT_LOG) {
453 // 判断传入 XML 格式信息是否为 null
454 if (isEmpty(xml)) {
455 printLog(Log.ERROR, tag, "Empty/Null xml content");
456 return;
457 }
458 try {
459 Source xmlInput = new StreamSource(new StringReader(xml));
460 StreamResult xmlOutput = new StreamResult(new StringWriter());
461 Transformer transformer = TransformerFactory.newInstance().newTransformer();
462 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
463 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
464 transformer.transform(xmlInput, xmlOutput);
465 // 获取打印消息
466 String message = xmlOutput.getWriter().toString().replaceFirst(">", ">\n");
467 // 打印信息
468 printLog(Log.DEBUG, tag, message);
469 } catch (Exception e) {
470 String errorInfo;
471 Throwable throwable = e.getCause();
472 if (throwable != null) {
473 errorInfo = throwable.toString();
474 } else {
475 try {
476 errorInfo = e.toString();
477 } catch (Exception e1) {
478 errorInfo = e1.toString();
479 }
480 }
481 printLog(Log.ERROR, tag, errorInfo + DevFinal.SYMBOL.NEW_LINE + xml);
482 }
483 }
484 }
485
486 // ==========
487 // = 通知输出 =

Callers 1

xmlMethod · 0.95

Calls 4

isEmptyMethod · 0.95
printLogMethod · 0.95
newInstanceMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected