Package org.more.xml.stream

Examples of org.more.xml.stream.StartElementEvent


    @Override
    public synchronized void sendEvent(final XmlStreamEvent e) throws XMLStreamException, IOException {
        //1.处理StartElementEvent
        if (e instanceof StartElementEvent) {
            this.activateStack.createStack();
            StartElementEvent ee = (StartElementEvent) e;
            //
            int nsCount = ee.getNamespaceCount();
            for (int i = 0; i < nsCount; i++) {
                String prefix = ee.getNamespacePrefix(i);
                String uri = ee.getNamespaceURI(i);
                prefix = prefix == null ? "" : prefix;
                NameSpace ns = this.activateStack.getNameSpace(prefix);
                if (ns == null) {
                    //激活新的命名空间
                    this.activateStack.addNameSpace(prefix, new NameSpace(uri, "/"));
                }
            }
            //生成当前节点的xpath(专属命名空间下的xpath)
            String prefix = ee.getPrefix();
            prefix = prefix == null ? "" : prefix;
            NameSpace ns = this.activateStack.getNameSpace(prefix);
            ns.appendXPath(ee.getElementName(), false);
            this.issueEvent(e, this.activateStack);
            //如果执行的是跳过则删除其加入的xpath,因为reader不会再发送其end事件。
            if (e.isSkip() == true) {
                ns.removeXPath();
            }
            return;
        } else
        //2.处理EndElementEvent
        if (e instanceof EndElementEvent) {
            EndElementEvent ee = (EndElementEvent) e;
            NameSpace ns = this.activateStack.getNameSpace(ee.getPrefix());
            this.issueEvent(e, this.activateStack);
            ns.removeXPath();
            this.activateStack.dropStack();
            return;
        } else
        //3.处理AttributeEvent
        if (e instanceof AttributeEvent) {
            this.activateStack.createStack();
            AttributeEvent ee = (AttributeEvent) e;
            String prefix = ee.getName().getPrefix();
            prefix = prefix == null ? "" : prefix;
            if (prefix.equals("") == true) {
                prefix = ee.getCurrentElement().getPrefix();
            }
            prefix = prefix == null ? "" : prefix;
            //
            NameSpace ns = this.activateStack.getNameSpace(prefix);
            ns.appendXPath(ee.getElementName(), true);
            this.issueEvent(e, this.activateStack);
            ns.removeXPath();
            this.activateStack.dropStack();
            return;
        } else
View Full Code Here

TOP

Related Classes of org.more.xml.stream.StartElementEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.