菜鸟自己写着玩
import org.springframework.web.bind.annotation.RequestBody;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.StringReader;
import java.util.HashMap;
public class test06 {
public static void generalXmlSync(@RequestBody String requestData) throws ParserConfigurationException, IOException, SAXException {
//String xml 转Document xml
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(requestData));
Document document = db.parse(is);
//通过Document对象的getElementsByTagName()返根节点的一个list集合
HashMap hashMap = new HashMap();
HashMap hashMapData = new HashMap();
NodeList booklist = document.getElementsByTagName("Aaa");
Object Id = null;
String values;
for (int i = 0; i < booklist.getLength(); i++) {
//循环遍历获取每一个book
Node book = booklist.item(i);
//通过Node对象的getAttributes()方法获取全的属性值
NamedNodeMap bookmap = book.getAttributes();
//循环遍每一个book的属性值
for (int j = 0; j < bookmap.getLength(); j+
解析XML字符串存入Map输出
本文将详细讲解如何将包含Aaa xmlns属性的XML字符串解析为Map,并重点讨论处理命名空间的方法,确保数据正确导入。通过示例代码,展示从XML到Map的转换过程,帮助读者理解这一常见操作。
摘要由CSDN通过智能技术生成