大家好,又见面了,我是你们的朋友全栈君。
package com.joyveb.addon.hp;
import java.io.StringReader;
import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader;
public class Snippet { public String getMsg(String xml){ SAXReader reader = new SAXReader(); try { Document document = reader.read(new StringReader(xml)); Element header = document.getRootElement().element(“header”); System.out.println(header.elementText(“transactionType”)); } catch (DocumentException e) { e.printStackTrace(); } return null; } public static void main(String[] args) { StringBuilder sb = new StringBuilder(); sb.append(“<?xml version=”1.0” encoding=”GBK”?>”) .append(“<message version=”1.1” id=””).append(“3”).append(“”>”) .append(“<header>”) .append(“<transactionType>105</transactionType>”) .append(“</header>”) .append(“</message>”); Snippet s = new Snippet(); s.getMsg(sb.toString()); } }
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148239.html原文链接:https://javaforall.cn