public static Map<String, String> convertToMap(String xml) {
		Map<String, String> map = new LinkedHashMap<String, String>();
		try {
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

			/*
			 * 避免 XXE 攻击
			 * 
			 * @since 2.8.21
			 */
			dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
			dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
			dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
			dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
			dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
			dbf.setXIncludeAware(false);
			dbf.setExpandEntityReferences(false);

			DocumentBuilder db = dbf.newDocumentBuilder();
			StringReader sr = new StringReader(xml);
			InputSource is = new InputSource(sr);
			Document document = db.parse(is);

			Element root = document.getDocumentElement();
			if (root != null) {
				NodeList childNodes = root.getChildNodes();
				if (childNodes != null && childNodes.getLength() > 0) {
					for (int i = 0; i < childNodes.getLength(); i++) {
						Node node = childNodes.item(i);
						if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
							map.put(node.getNodeName(), node.getTextContent());
						}
					}
				}
			}
		} catch (Exception e) {
			logger.error("", e);
		}
		return map;
	}
public static Map < String , String > convertToMap ( String xml ) { Map < String , String > map = new LinkedHashMap < String , String > ( ) ; try { DocumentBuilderFactory dbf = DocumentBuilderFactory . newInstance ( ) ; dbf . setFeature ( "http://apache.org/xml/features/disallow-doctype-decl" , true ) ; dbf . setFeature ( "http://xml.org/sax/features/external-general-entities" , false ) ; dbf . setFeature ( "http://xml.org/sax/features/external-parameter-entities" , false ) ; dbf . setFeature ( "http://apache.org/xml/features/nonvalidating/load-external-dtd" , false ) ; dbf . setFeature ( XMLConstants . FEATURE_SECURE_PROCESSING , true ) ; dbf . setXIncludeAware ( false ) ; dbf . setExpandEntityReferences ( false ) ; DocumentBuilder db = dbf . newDocumentBuilder ( ) ; StringReader sr = new StringReader ( xml ) ; InputSource is = new InputSource ( sr ) ; Document document = db . parse ( is ) ; Element root = document . getDocumentElement ( ) ; if ( root != null ) { NodeList childNodes = root . getChildNodes ( ) ; if ( childNodes != null && childNodes . getLength ( ) > 0 ) { for ( int i = 0 ; i < childNodes . getLength ( ) ; i ++ ) { Node node = childNodes . item ( i ) ; if ( node != null && node . getNodeType ( ) == Node . ELEMENT_NODE ) { map . put ( node . getNodeName ( ) , node . getTextContent ( ) ) ; } } } } } catch ( Exception e ) { logger . error ( "" , e ) ; } return map ; }
转换简单的xml to map

@param xml
xml
@return map