xmlparsertestutil.java

来自「yahoo api,包括各版本的」· Java 代码 · 共 35 行

JAVA
35
字号
package com.yahoo;import com.yahoo.java.ExtendedError;import com.yahoo.search.SearchException;import com.yahoo.xml.XmlParser;import org.xml.sax.SAXException;import javax.xml.parsers.ParserConfigurationException;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import java.util.Map;public class XmlParserTestUtil {    public static Map parseTest(String xmlPath) throws Exception {        XmlParser xmlParser = null;        if(xmlPath == null) {            throw new Exception("xmlPath hasn't been specified, unable to parse");        }        try {            SAXParser parser = SAXParserFactory.newInstance().newSAXParser();            xmlParser = new XmlParser();            parser.parse(XmlParserTestUtil.class.getResourceAsStream(xmlPath), xmlParser);        }        catch (ParserConfigurationException e) {            throw new ExtendedError("XML parser not properly configured", e);        }        catch (SAXException e) {            throw new SearchException("Error parsing XML response", e);        }        return xmlParser.getRoot();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?