当前位置: 首页>>代码示例>>Java>>正文


Java SAXReader类代码示例

本文整理汇总了Java中org.dom4j.io.SAXReader的典型用法代码示例。如果您正苦于以下问题:Java SAXReader类的具体用法?Java SAXReader怎么用?Java SAXReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SAXReader类属于org.dom4j.io包,在下文中一共展示了SAXReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: query_timestamp

import org.dom4j.io.SAXReader; //导入依赖的package包/类
/**
    * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
    * 注意:远程解析XML出错,与服务器是否支持SSL等配置有关
    * @return 时间戳字符串
    * @throws IOException
    * @throws DocumentException
    * @throws MalformedURLException
    */
public static String query_timestamp() throws MalformedURLException,
                                                       DocumentException, IOException {

       //构造访问query_timestamp接口的URL串
       String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" +AlipayConfig.input_charset;
       StringBuffer result = new StringBuffer();

       SAXReader reader = new SAXReader();
       Document doc = reader.read(new URL(strUrl).openStream());

       List<Node> nodeList = doc.selectNodes("//alipay/*");

       for (Node node : nodeList) {
           // 截取部分不需要解析的信息
           if (node.getName().equals("is_success") && node.getText().equals("T")) {
               // 判断是否有成功标示
               List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
               for (Node node1 : nodeList1) {
                   result.append(node1.getText());
               }
           }
       }

       return result.toString();
   }
 
开发者ID:dianbaer,项目名称:epay,代码行数:34,代码来源:AlipaySubmit.java

示例2: readSettingsFile

import org.dom4j.io.SAXReader; //导入依赖的package包/类
public static DOM4JSettingsNode readSettingsFile(ImportInteraction importInteraction, FileFilter fileFilter) {
    File file = importInteraction.promptForFile(fileFilter);
    if (file == null) {
        return null;
    }

    if (!file.exists()) {
        importInteraction.reportError("File does not exist: " + file.getAbsolutePath());
        return null;  //we should really sit in a loop until they cancel or give us a valid file.
    }

    try {
        SAXReader reader = new SAXReader();
        Document document = reader.read(file);

        return new DOM4JSettingsNode(document.getRootElement());
    } catch (Throwable t) {
        LOGGER.error("Unable to read file: " + file.getAbsolutePath(), t);
        importInteraction.reportError("Unable to read file: " + file.getAbsolutePath());
        return null;
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:23,代码来源:DOM4JSerializer.java

示例3: parseText

import org.dom4j.io.SAXReader; //导入依赖的package包/类
public static Document parseText(String text) throws DocumentException, SAXException {
    SAXReader reader = new SAXReader(false);
    reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    reader.setFeature("http://apache.org/xml/features/validation/schema", false);
    String encoding = getEncoding(text);

    InputSource source = new InputSource(new StringReader(text));
    source.setEncoding(encoding);

    Document result = reader.read(source);

    // if the XML parser doesn't provide a way to retrieve the encoding,
    // specify it manually
    if (result.getXMLEncoding() == null) {
        result.setXMLEncoding(encoding);
    }

    return result;
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:20,代码来源:DaoGenHelper.java

示例4: query_timestamp

import org.dom4j.io.SAXReader; //导入依赖的package包/类
/**
 * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
 * 注意:远程解析XML出错,与服务器是否支持SSL等配置有关
 *
 * @return 时间戳字符串
 * @throws IOException
 * @throws DocumentException
 * @throws MalformedURLException
 */
public static String query_timestamp() throws MalformedURLException, DocumentException, IOException {

	//构造访问query_timestamp接口的URL串
	String strUrl = PayManager.HTTPS_MAPI_ALIPAY_COM_GATEWAY_DO + "?" + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" + AlipayConfig.input_charset;
	StringBuffer result = new StringBuffer();

	SAXReader reader = new SAXReader();
	Document doc = reader.read(new URL(strUrl).openStream());

	List<Node> nodeList = doc.selectNodes("//alipay/*");

	for (Node node : nodeList) {
		// 截取部分不需要解析的信息
		if (node.getName().equals("is_success") && node.getText().equals("T")) {
			// 判断是否有成功标示
			List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
			for (Node node1 : nodeList1) {
				result.append(node1.getText());
			}
		}
	}

	return result.toString();
}
 
开发者ID:funtl,项目名称:framework,代码行数:34,代码来源:AlipaySubmit.java

示例5: XMLBeanFactory

import org.dom4j.io.SAXReader; //导入依赖的package包/类
public XMLBeanFactory(InputStream input) {
    SAXReader reader = new SAXReader();
    Document doc = null;
    try {
        doc = reader.read(input);
        if (doc == null)
            return;
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    Element root = doc.getRootElement();
            
    @SuppressWarnings("unchecked")
    List<Element> beanElems = root.elements();
    for (Element beanElem : beanElems) {
        Bean bean = parseBeanElement(beanElem);

        addBean(bean);
    }
    
    instancetiateSingletons();
}
 
开发者ID:hulang1024,项目名称:SummerFramework,代码行数:23,代码来源:XMLBeanFactory.java

示例6: convert

import org.dom4j.io.SAXReader; //导入依赖的package包/类
/**
 * 属性转化
 * @param xmlFile xml文件
 */
private void convert(File xmlFile){
    SAXReader reader = new SAXReader();
    try {
        Document document = reader.read(xmlFile);
        Element root = document.getRootElement();
        root.element("id").setText(artifactId);
        root.element("name").setText(getJarPrefixName());
        root.element("description").setText(null == description ? "暂无描述" : description);
        String javaArguments = "";
        if (arguments != null) {
            for (String argument : arguments) {
                javaArguments = " " + argument;
            }
        }
        root.element("arguments").setText("-jar " + getJarName() + javaArguments);
        saveXML(document,xmlFile);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:JoyLau,项目名称:joylau-springboot-daemon-windows,代码行数:25,代码来源:WindowsServiceMojo.java

示例7: readXML

import org.dom4j.io.SAXReader; //导入依赖的package包/类
public String readXML(int xmlId, String textItem, int textId){
	String xmlText;
	String xmlPath;
	Element xmlRoot,secRoot;
	URL xmlURL;
	Document xmlFile;
	SAXReader reader = new SAXReader();
	xmlPath = "./data/language/" +
			language +
			"/" +
			rEadC.getConfig(rEadC.userConfig , "text", "xml" + xmlId);
	xmlURL = Resources.getResource(xmlPath);
	try {
		xmlFile = reader.read(xmlURL);
		xmlRoot = xmlFile.getRootElement();
		secRoot = xmlRoot.element(textItem);
		xmlText = secRoot.elementText("adv" + textId);
		return xmlText;
	} catch (DocumentException e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:pokemonchw,项目名称:chiefproject,代码行数:24,代码来源:ReadXml.java

示例8: parseXml

import org.dom4j.io.SAXReader; //导入依赖的package包/类
/**
 * 解析微信发来的请求(XML)
 *
 * @param request
 * @return Map<String, String>
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public static Map<String, String> parseXml(HttpServletRequest request) throws Exception {
    // 将解析结果存储在HashMap中
    Map<String, String> map = new HashMap<String, String>();

    // 从request中取得输入流
    InputStream inputStream = request.getInputStream();
    // 读取输入流
    SAXReader reader = new SAXReader();
    Document document = reader.read(inputStream);
    // 得到xml根元素
    Element root = document.getRootElement();
    // 得到根元素的所有子节点
    List<Element> elementList = root.elements();

    // 遍历所有子节点
    for (Element e : elementList)
        map.put(e.getName(), e.getText());

    // 释放资源
    inputStream.close();
    inputStream = null;

    return map;
}
 
开发者ID:Evan1120,项目名称:wechat-api-java,代码行数:33,代码来源:MessageUtil.java

示例9: loadQueryCollection

import org.dom4j.io.SAXReader; //导入依赖的package包/类
public void loadQueryCollection(String location)
{
    try
    {
        InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
        SAXReader reader = new SAXReader();
        Document document = reader.read(is);
        is.close();
        QueryCollection collection = QueryCollectionImpl.createQueryCollection(document.getRootElement(), dictionaryService, namespaceService);
        collections.put(location, collection);
    }
    catch (DocumentException de)
    {
        throw new AlfrescoRuntimeException("Error reading XML", de);
    }
    catch (IOException e)
    {
        throw new AlfrescoRuntimeException("IO Error reading XML", e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:21,代码来源:QueryRegisterComponentImpl.java

示例10: hasRoot

import org.dom4j.io.SAXReader; //导入依赖的package包/类
public static boolean hasRoot(File file, String name)
{
    SAXReader reader = new SAXReader();
    try(InputStream in = new FileInputStream(file))
    {
        Document doc = reader.read(in);
        Element rootEle = doc.getRootElement();
        String rootEleName = rootEle.getName();

        return rootEleName.equals(name);
    }
    catch (Exception e)
    {}

    return false;
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.suite.runner,代码行数:17,代码来源:XmlUtils.java

示例11: query_timestamp

import org.dom4j.io.SAXReader; //导入依赖的package包/类
/**
    * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
    * 注意:远程解析XML出错,与服务器是否支持SSL等配置有关
    * @return 时间戳字符串
    * @throws IOException
    * @throws DocumentException
    * @throws MalformedURLException
    */
public static String query_timestamp(AlipayConfig config) throws MalformedURLException,
                                                       DocumentException, IOException {

       //构造访问query_timestamp接口的URL串
       String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + config.getPartnerId() + "&_input_charset" +AlipayConfig.inputCharset;
       StringBuffer result = new StringBuffer();

       SAXReader reader = new SAXReader();
       Document doc = reader.read(new URL(strUrl).openStream());

       List<Node> nodeList = doc.selectNodes("//alipay/*");

       for (Node node : nodeList) {
           // 截取部分不需要解析的信息
           if (node.getName().equals("is_success") && node.getText().equals("T")) {
               // 判断是否有成功标示
               List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
               for (Node node1 : nodeList1) {
                   result.append(node1.getText());
               }
           }
       }

       return result.toString();
   }
 
开发者ID:superkoh,项目名称:k-framework,代码行数:34,代码来源:AlipaySubmit.java

示例12: getCollectionDocumentFromWebService

import org.dom4j.io.SAXReader; //导入依赖的package包/类
private Document getCollectionDocumentFromWebService ( String _key )
{
	Document collectionDocument = null;

	// make the call to DDS and get ListCollections 
	try {
		URLConnection connection = new URL ("http://www.dlese.org/dds/services/ddsws1-1?verb=Search&ky=" + _key + "&n=200&s=0" ).openConnection();
		
        connection.setDoOutput( true );
        connection.setDoInput(true);
        
        ((HttpURLConnection)connection).setRequestMethod("GET");
        		    
	    SAXReader xmlReader = new SAXReader();
	    
	    collectionDocument = xmlReader.read(connection.getInputStream());	
	            
	} catch ( Exception e ) {
		e.printStackTrace();
	}		
	
	return collectionDocument;
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:24,代码来源:CollectionImporter.java

示例13: getValidMetadataFormats

import org.dom4j.io.SAXReader; //导入依赖的package包/类
/**
 *  Grabs the valid metadata formats from the DPC schema.
 *
 * @return    A list of valid metadata formats.
 */
public ArrayList getValidMetadataFormats() {
	String metadataFormatSchemaUrl =
		getServlet().getServletContext().getInitParameter("metadataFormatSchemaUrl");
	if (metadataFormatSchemaUrl == null)
		return null;

	if (validMetadataFormats == null) {
		try {
			validMetadataFormats = new ArrayList();
			SAXReader reader = new SAXReader();
			Document document = reader.read(new URL(metadataFormatSchemaUrl));
			validMetadataFormats.add("-- SELECT FORMAT --");
			List nodes = document.selectNodes("//xsd:simpleType[@name='itemFormatType']/xsd:restriction/xsd:enumeration");
			for (Iterator iter = nodes.iterator(); iter.hasNext(); ) {
				Node node = (Node) iter.next();
				validMetadataFormats.add(node.valueOf("@value"));
			}
		} catch (Throwable e) {
			prtlnErr("Error getValidMetadataFormats(): " + e);
			validMetadataFormats = null;
		}
	}
	return validMetadataFormats;
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:30,代码来源:RepositoryAdminForm.java

示例14: getConfig

import org.dom4j.io.SAXReader; //导入依赖的package包/类
@Override
public Element getConfig() {
    final File boardFile = new File(getConfigFile());
    if (boardFile.exists()) {
        try {
            return new SAXReader(false).read(boardFile).getRootElement();
        } catch (DocumentException ex) {
            QLog.l().logger()
                .error("Невозможно прочитать файл конфигурации главного табло. " + ex
                    .getMessage());
            return DocumentHelper.createElement("Ответ");
        }
    } else {
        QLog.l().logger()
            .warn("Файл конфигурации главного табло \"" + configFile + "\" не найден. ");
        return DocumentHelper.createElement("Ответ");
    }
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:19,代码来源:QIndicatorBoardMonitor.java

示例15: getValidCollectionKeys

import org.dom4j.io.SAXReader; //导入依赖的package包/类
/**
 *  Grabs the collection keys from the DPC keys schema.
 *
 * @return    A list of valid colleciton keys.
 */
public ArrayList getValidCollectionKeys() {
	String collectionKeySchemaUrl =
		getServlet().getServletContext().getInitParameter("collectionKeySchemaUrl");
	if (collectionKeySchemaUrl == null)
		return null;

	if (validCollectionKeys == null) {
		try {
			validCollectionKeys = new ArrayList();
			SAXReader reader = new SAXReader();
			Document document = reader.read(new URL(collectionKeySchemaUrl));
			validCollectionKeys.add("-- SELECT COLLECTION KEY --");
			List nodes = document.selectNodes("//xsd:simpleType[@name='keyType']/xsd:restriction/xsd:enumeration");
			for (Iterator iter = nodes.iterator(); iter.hasNext(); ) {
				Node node = (Node) iter.next();
				validCollectionKeys.add(node.valueOf("@value"));
			}
		} catch (Throwable e) {
			prtlnErr("Error getCollectionKeys(): " + e);
			validCollectionKeys = null;
		}
	}
	return validCollectionKeys;
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:30,代码来源:DCSAdminForm.java


注:本文中的org.dom4j.io.SAXReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。