當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLEvent類代碼示例

本文整理匯總了Java中javax.xml.stream.events.XMLEvent的典型用法代碼示例。如果您正苦於以下問題:Java XMLEvent類的具體用法?Java XMLEvent怎麽用?Java XMLEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XMLEvent類屬於javax.xml.stream.events包,在下文中一共展示了XMLEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCreateStartDocument_DOMWriter

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
/**
 * @bug 8139584
 * Verifies that the resulting XML contains the standalone setting.
 */
@Test
public void testCreateStartDocument_DOMWriter()
        throws ParserConfigurationException, XMLStreamException {

    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    XMLEventWriter eventWriter = xof.createXMLEventWriter(new DOMResult(doc));
    XMLEventFactory eventFactory = XMLEventFactory.newInstance();
    XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true);
    eventWriter.add(event);
    eventWriter.flush();
    Assert.assertEquals(doc.getXmlEncoding(), "iso-8859-15");
    Assert.assertEquals(doc.getXmlVersion(), "1.0");
    Assert.assertTrue(doc.getXmlStandalone());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:XMLStreamWriterTest.java

示例2: getAttributeValue

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
/**
 * @param namespaceURI
 * @param localName
 * @return
 */
public String getAttributeValue(String namespaceURI, String localName) {
    //State should be either START_ELEMENT or ATTRIBUTE
    if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
        XMLAttributesImpl attributes = fScanner.getAttributeIterator();
        if (namespaceURI == null) { //sjsxp issue 70
            return attributes.getValue(attributes.getIndexByLocalName(localName)) ;
        } else {
            return fScanner.getAttributeIterator().getValue(
                    namespaceURI.length() == 0 ? null : namespaceURI, localName) ;
        }

    } else{
        throw new java.lang.IllegalStateException("Current state is not among the states "
                 + getEventTypeString(XMLEvent.START_ELEMENT) + " , "
                 + getEventTypeString(XMLEvent.ATTRIBUTE)
                 + "valid for getAttributeValue()") ;
    }

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:XMLStreamReaderImpl.java

示例3: fromXml

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
public static TsoFrequencySecurityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
    String text = null;
    while (xmlsr.hasNext()) {
        int eventType = xmlsr.next();
        switch (eventType) {
            case XMLEvent.CHARACTERS:
                text = xmlsr.getText();
                break;
            case XMLEvent.END_ELEMENT:
                if ("freq-out-count".equals(xmlsr.getLocalName())) {
                    return new TsoFrequencySecurityIndex(contingencyId, Integer.parseInt(text));
                }
                break;
            default:
                break;
        }
    }
    throw new AssertionError("freq-out-count element not found");
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:20,代碼來源:TsoFrequencySecurityIndex.java

示例4: eventReaderTest

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
public void eventReaderTest(XMLInputFactory xif) {
    XMLEventReader eventReader = null;
    try {
        eventReader = xif.createXMLEventReader(this.getClass().getResourceAsStream(INPUT_FILE));
        XMLEventReader filteredEventReader = xif.createFilteredReader(eventReader, new EventFilter() {
            public boolean accept(XMLEvent event) {
                if (!event.isStartElement()) {
                    return false;
                }
                QName elementQName = event.asStartElement().getName();
                if ((elementQName.getLocalPart().equals(ATTACHMENT_NAME.getLocalPart()) || elementQName.getLocalPart().equals("Attachment"))
                        && elementQName.getNamespaceURI().equals(VF_GENERIC_TT_NAMESPACE)) {
                    return true;
                }
                return false;
            }
        });
        if (filteredEventReader.hasNext()) {
            System.out.println("containsAttachments() returns true");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());

    } finally {
        if (eventReader != null) {
            try {
                eventReader.close();
            } catch (XMLStreamException xse) {
                // Ignored by intention
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:Bug6976938Test.java

示例5: nextTag

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
@Override
public final XMLEvent nextTag() throws XMLStreamException {
	XMLEvent event = this.nextEvent();
	while ((event.isCharacters() && event.asCharacters().isWhiteSpace())
			|| event.isProcessingInstruction()
			|| event.getEventType() == XMLStreamConstants.COMMENT) {

		event = this.nextEvent();
	}

	if (!event.isStartElement()  && event.isEndElement()) {
		throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
	}

	return event;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:BaseXMLEventReader.java

示例6: reset

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
public void reset(PropertyManager propertyManager) {
    super.reset(propertyManager);
    // other settings
    fDoctypeName = null;
    fDoctypePublicId = null;
    fDoctypeSystemId = null;
    fSeenDoctypeDecl = false;
    fNamespaceContext.reset();
    fSupportDTD = ((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue();

    // xerces features
    fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue();
    setScannerState(XMLEvent.START_DOCUMENT);
    setDriver(fXMLDeclDriver);
    fSeenInternalSubset = false;
    if(fDTDScanner != null){
        ((XMLDTDScannerImpl)fDTDScanner).reset(propertyManager);
    }
    fEndPos = 0;
    fStartPos = 0;
    if(fDTDDecl != null){
        fDTDDecl.clear();
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:XMLDocumentScannerImpl.java

示例7: toDom4jDocument

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
private Document toDom4jDocument(XMLEventReader staxEventReader, Origin origin) {
	STAXEventReader dom4jStaxEventReader = new STAXEventReader();
	try {
		// the dom4j converter class is touchy about comments (aka, comments make it implode)
		// so wrap the event stream in a filtering stream to filter out comment events
		staxEventReader = new FilteringXMLEventReader( staxEventReader ) {
			@Override
			protected XMLEvent filterEvent(XMLEvent event, boolean peek) {
				return event.getEventType() == XMLStreamConstants.COMMENT
						? null
						: event;
			}
		};

		return dom4jStaxEventReader.readDocument( staxEventReader );
	}
	catch (XMLStreamException e) {
		throw new InvalidMappingException( "Unable to read StAX source as dom4j Document for processing", origin, e );
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:MappingReader.java

示例8: getElementText

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
public String getElementText() throws XMLStreamException
{
    StringBuffer buffer = new StringBuffer();
    XMLEvent e = nextEvent();
    if (!e.isStartElement())
        throw new XMLStreamException(
        CommonResourceBundle.getInstance().getString("message.mustBeOnSTART_ELEMENT"));

    while(hasNext()) {
        e = nextEvent();
        if(e.isStartElement())
            throw new XMLStreamException(
            CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly"));
        if(e.isCharacters())
            buffer.append(((Characters) e).getData());
        if(e.isEndElement())
            return buffer.toString();
    }
    throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.END_ELEMENTnotFound"));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:StAXFilteredEvent.java

示例9: readText

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
/**
 * Returns the text contents of the current element being parsed.
 *
 * @return The text contents of the current element being parsed.
 * @throws XMLStreamException
 */
public String readText() throws XMLStreamException {
    if (isInsideResponseHeader()) {
        return getHeader(currentHeader);
    }
    if (currentEvent.isAttribute()) {
        Attribute attribute = (Attribute)currentEvent;
        return attribute.getValue();
    }

    StringBuilder sb = new StringBuilder();
    while (true) {
        XMLEvent event = eventReader.peek();
        if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
            eventReader.nextEvent();
            sb.append(event.asCharacters().getData());
        } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT) {
            return sb.toString();
        } else {
            throw new RuntimeException("Encountered unexpected event: " + event.toString());
        }
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:29,代碼來源:StaxUnmarshallerContext.java

示例10: handleStartDocument

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
private void handleStartDocument(final XMLEvent event) throws SAXException {
    _sax.setDocumentLocator(new Locator2() {
        public int getColumnNumber() {
            return event.getLocation().getColumnNumber();
        }
        public int getLineNumber() {
            return event.getLocation().getLineNumber();
        }
        public String getPublicId() {
            return event.getLocation().getPublicId();
        }
        public String getSystemId() {
            return event.getLocation().getSystemId();
        }
        public String getXMLVersion(){
            return version;
        }
        public String getEncoding(){
            return encoding;
        }

    });
    _sax.startDocument();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:StAXEvent2SAX.java

示例11: testLocation

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
@Test
public void testLocation() {
    String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n"
            + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n"
            + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>\n" + "<root />";

    try {
        XMLEventReader er = getReader(XML);
        XMLEvent evt = er.nextEvent(); // StartDocument
        Location loc1 = evt.getLocation();
        System.out.println("Location 1: " + loc1.getLineNumber() + "," + loc1.getColumnNumber());
        evt = er.nextEvent(); // DTD
        // loc1 should not change so its line number should still be 1
        Assert.assertTrue(loc1.getLineNumber() == 1);
        Location loc2 = evt.getLocation();
        System.out.println("Location 2: " + loc2.getLineNumber() + "," + loc2.getColumnNumber());
        evt = er.nextEvent(); // root
        System.out.println("Location 1: " + loc1.getLineNumber() + "," + loc1.getColumnNumber());
        Assert.assertTrue(loc1.getLineNumber() == 1);
        Assert.assertTrue(loc2.getLineNumber() == 7);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:Issue58Test.java

示例12: testCR6419687

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
/**
 * Test: 6419687 NPE in XMLEventWriterImpl.
 */
@Test
public void testCR6419687() {

    try {
        InputStream in = getClass().getResourceAsStream("ReaderToWriterTest.wsdl");
        OutputStream out = new FileOutputStream(USER_DIR + "ReaderToWriterTest-out.xml");

        XMLEventReader reader = XML_INPUT_FACTORY.createXMLEventReader(in);
        XMLEventWriter writer = XML_OUTPUT_FACTORY.createXMLEventWriter(out, "UTF-8");
        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            writer.add(event);
        }
        reader.close();
        writer.close();
    } catch (XMLStreamException xmlStreamException) {
        xmlStreamException.printStackTrace();
        Assert.fail(xmlStreamException.toString());
    } catch (FileNotFoundException fileNotFoundException) {
        fileNotFoundException.printStackTrace();
        Assert.fail(fileNotFoundException.toString());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:ReaderToWriterTest.java

示例13: getAttributeValue

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
/**
 * @param namespaceURI
 * @param localName
 * @return
 */
public String getAttributeValue(String namespaceURI, String localName) {
    //State should be either START_ELEMENT or ATTRIBUTE
    if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
        XMLAttributesImpl attributes = fScanner.getAttributeIterator();
        if (namespaceURI == null) { //sjsxp issue 70
            return attributes.getValue(attributes.getIndexByLocalName(localName));
        } else {
            return fScanner.getAttributeIterator().getValue(
                    namespaceURI.length() == 0 ? null : namespaceURI, localName);
        }

    } else {
        throw new java.lang.IllegalStateException("Current state is not among the states "
                + getEventTypeString(XMLEvent.START_ELEMENT) + " , "
                + getEventTypeString(XMLEvent.ATTRIBUTE)
                + "valid for getAttributeValue()");
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:XMLStreamReaderImpl.java

示例14: switchToXML11Scanner

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
private void switchToXML11Scanner() throws IOException{

        int oldEntityDepth = fScanner.fEntityDepth;
        com.sun.org.apache.xerces.internal.xni.NamespaceContext oldNamespaceContext = fScanner.fNamespaceContext;

        fScanner = new XML11NSDocumentScannerImpl();

        //get the new scanner state to old scanner's previous state
        fScanner.reset(fPropertyManager);
        fScanner.setPropertyManager(fPropertyManager);
        fEntityScanner = (XMLEntityScanner)fEntityManager.getEntityScanner()  ;
        fEntityManager.fCurrentEntity.mayReadChunks = true;
        fScanner.setScannerState(XMLEvent.START_DOCUMENT);

        fScanner.fEntityDepth = oldEntityDepth;
        fScanner.fNamespaceContext = oldNamespaceContext;
        fEventType = fScanner.next();
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:XMLStreamReaderImpl.java

示例15: getCharacterData

import javax.xml.stream.events.XMLEvent; //導入依賴的package包/類
/**
 * Reads the data from the {@link XMLEvent} and returns it. CData
 * will be handled special.
 * @param event {@link XMLEvent}
 * @param eventReader Reader for Reading {@link XMLEvent}
 * @return Character data from element
 * @throws XMLStreamException
 */
private String getCharacterData(XMLEvent event, final XMLEventReader eventReader) throws XMLStreamException {
	String result = "";
	event = eventReader.nextEvent();
	if (event instanceof Characters) {
		result = event.asCharacters().getData();
	}
	return result;
}
 
開發者ID:XMBomb,項目名稱:InComb,代碼行數:17,代碼來源:AXMLParser.java


注:本文中的javax.xml.stream.events.XMLEvent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。