public String getXmlContent(String url,Long courseId) throws Exception {
Map<String,Object> contentMap = new HashMap<String,Object>();
contentMap.put("id", courseId);
contentMap.put("coreXmlName", "aa.xml");
// 创建SAXReader对象
SAXReader reader = new SAXReader();
// 读取XML文件结构
URL getUrl = new URL("http://yinzongchao.cn/xml/2019/aa.xml");//域名路径
// File file = new File("d://aa.txt");
HttpURLConnection conn = (HttpURLConnection) getUrl.openConnection();
InputStream in = conn.getInputStream();
Document doc = reader.read(in);
// 获取XML文件根节点
Element root = doc.getRootElement();
String id = root.attributeValue("id");
contentMap.put("code", id);
String name = root.attributeValue("name");
contentMap.put("name", name);
// 获取根节点一下的子元素
List<Element> list = root.elements();
for (Element item : list) {
if("sug".equals(item.getName())){
contentMap.put("sug", item.getStringValue());
}else if("object".equals(item.getName())){
contentMap.put("objec", item.getStringValue());
}else if("diff".equals(item.getName())){
List<List<String>> diffList = new ArrayList<List<String>>();
List<Element> seclist = item.elements();
for (Element element : seclist) {
List<String> diff = new ArrayList<String>();
Element diffNode = element.element("diff");
diff.add(element.attributeValue("title"));
diff.add(element.attributeValue("level"));
diffList.add(diff);
}
contentMap.put("diffi", diffList);
}else if("content".equals(item.getName())){
}
}
return null;
}
java读取域名下的xml文件内容
最新推荐文章于 2022-11-19 13:39:48 发布