Esper事件处理引擎_4_XML 数据结构处理

前端之家收集整理的这篇文章主要介绍了Esper事件处理引擎_4_XML 数据结构处理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

参考博客栏目 :http://blog.csdn.net/column/details/esper.html

Esper 事件引擎栏目:http://blog.csdn.net/xiaohulunb/article/category/2436609

GitHub代码地址:https://github.com/xiaohulu/my_note/tree/master/src/main/java/com/framework_technology/esper


XML 数据结构

测试未成功,待解决
代码引用的 xml/xsd 以 GitHub中为主。


package com.framework_technology.esper.event_type;

import com.espertech.esper.client.ConfigurationEventTypeXMLDOM;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.StringReader;
import java.net.URL;

/**
 * Created by IntelliJ IDEA.
 * User: wei.Li
 * Date: 14-7-28
 * Time: 17:57
 * TODO unfinished
 */
public class XML_EventType {


    public void getA() throws ParserConfigurationException,IOException,SAXException {
        URL schemaURL = this.getClass().getClassLoader().getResource("sensor.xsd");
        URL xml = this.getClass().getClassLoader().getResource("sensor.xml");

        EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
        ConfigurationEventTypeXMLDOM sensorcfg = new ConfigurationEventTypeXMLDOM();
        sensorcfg.setRootElementName("Sensor");
        sensorcfg.setSchemaResource(schemaURL.toString());
        epService.getEPAdministrator().getConfiguration()
                .addEventType("SensorEvent",sensorcfg);

        String epl = "select ID,Observation.Command,Observation.ID," +
                "  Observation.Tag[0].ID,Observation.Tag[1].ID" +
                "from SensorEvent";

        InputSource source = new InputSource(new StringReader(xml.toString()));
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setNamespaceAware(true);
        Document doc = builderFactory.newDocumentBuilder().parse(source);

        epService.getEPRuntime().sendEvent(doc);
    }

    public static void main(String[] args) throws ParserConfigurationException,SAXException {
        XML_EventType xml_eventType = new XML_EventType();
        xml_eventType.getA();
    }

}

猜你在找的XML相关文章