package org.jeecg.modules.callback.aesUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.callback.Vo.LiveBroadcastVo;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;
import java.util.Arrays;
/**
* @author feilong
* @date 2023/8/17
*/
public class XmlParseUtil {
public static JSONObject parseXml(String xmlStr) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
StringReader sr = new StringReader(xmlStr);
InputSource is = new InputSource(sr);
Document document = db.parse(is);
Element root = document.getDocumentElement();
NodeList nodelist = root.getChildNodes();
JSONObject json = new JSONObject();
for(int i=0;i<nodelist.getLength();i++){
String nodeName = nodelist.item(i).getNodeName();
NodeList nodelist1 = root.getElementsByTagName(nodeName);
String content = nodelist1.item(0).getTextContent();
json.put(nodeName,content);
}
return json;
}
}
解析xml数据工具类
最新推荐文章于 2024-05-30 11:43:13 发布