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


Java XMLEventReader类代码示例

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


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

示例1: testXMLStreamWriter

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
/**
 * Test XMLStreamWriter parsing a file with an external entity reference.
 */
@Test
public void testXMLStreamWriter() {

    try {
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(System.out);
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        String file = getClass().getResource("XMLEventWriterTest.xml").getPath();
        XMLEventReader eventReader = inputFactory.createXMLEventReader(new StreamSource(new File(file)));

        // adds the event to the consumer.
        eventWriter.add(eventReader);
        eventWriter.flush();
        eventWriter.close();

        // expected success
    } catch (Exception exception) {
        exception.printStackTrace();
        Assert.fail(exception.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:XMLEventWriterTest.java

示例2: AtomParser

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
public AtomParser(final ContentSource contentSource, final InputStream inputStream) {
	super(contentSource, inputStream);

	availableSetters = new String [] {"setTitle", "setUpdated", "setLink", "setContent", "setPublished"};

	try {
		startElementMethods.put(TAG_FEED,        ObjectUtil.assertNotNull(getDeclaredMethod("createParsingElement", String.class, XMLEvent.class, XMLEventReader.class), TAG_FEED));
		startElementMethods.put(TAG_ENTRY,       ObjectUtil.assertNotNull(getDeclaredMethod("pushElementIntoMap", String.class, XMLEvent.class, XMLEventReader.class), TAG_ENTRY));

		// used for the feed and entry
		startElementMethods.put(TAG_UPDATED,	 ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), TAG_UPDATED));

		// used only in entry
		startElementMethods.put(TAG_TITLE,       ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), TAG_TITLE));
		startElementMethods.put(TAG_LINK,        ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), TAG_LINK));
		startElementMethods.put(TAG_CONTENT, 	 ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), TAG_CONTENT));
		startElementMethods.put(TAG_PUBLISHED,   ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), TAG_PUBLISHED));

		endElementMehods.put(TAG_ENTRY,          ObjectUtil.assertNotNull(getDeclaredMethod("popElementFromStack"), TAG_ENTRY));

		specialMethods.put(TAG_ENTRY,            ObjectUtil.assertNotNull(getDeclaredMethod("createItemObject"), TAG_ENTRY));

	} catch (final SecurityException e) {
		LOGGER.error("Failed creating {} because", getClass(), e );
	}
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:27,代码来源:AtomParser.java

示例3: testEventReader2

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
@Test
public void testEventReader2() {
    try {
        // Now advance underlying reader and then call peek on event reader
        XMLStreamReader s1 = inputFactory.createXMLStreamReader(new java.io.StringReader(xml));
        Assert.assertEquals(s1.getEventType(), XMLStreamConstants.START_DOCUMENT);
        s1.next();
        s1.next(); // advance to <TITLE>
        Assert.assertTrue(s1.getLocalName().equals("TITLE"));

        XMLEventReader e3 = inputFactory.createXMLEventReader(s1);
        Assert.assertEquals(e3.peek().getEventType(), XMLStreamConstants.START_ELEMENT);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Bug6489502.java

示例4: test

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
@Test
public void test() {
    String xmlData = "<?xml version=\"1.0\"?><Test>Hello</Test>";
    try {
        XMLEventReader xmlReader = XMLInputFactory.newInstance().createXMLEventReader(new ByteArrayInputStream(xmlData.getBytes()));

        XMLEvent event = xmlReader.nextEvent();
        System.out.println(event.getClass());

        // xmlReader.peek(); // error in both cases with/without peek()
        event = xmlReader.nextTag(); // nextEvent() would work fine
        // nextTag() forgets to set fLastEvent
        System.out.println(event.getClass());

        String text = xmlReader.getElementText();
        System.out.println(text);
    } catch (XMLStreamException e) {
        Assert.fail(e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:Bug6586466Test.java

示例5: unmarshal

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
public JaxbRoot unmarshal(InputStream stream, Origin origin) {
	try {
		XMLEventReader staxReader = staxFactory().createXMLEventReader( stream );
		try {
			return unmarshal( staxReader, origin );
		}
		finally {
			try {
				staxReader.close();
			}
			catch ( Exception ignore ) {
			}
		}
	}
	catch ( XMLStreamException e ) {
		throw new MappingException( "Unable to create stax reader", e, origin );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:JaxbHelper.java

示例6: unmarshal

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
public JaxbHibernateConfiguration unmarshal(InputStream stream, Origin origin) {
	try {
		XMLEventReader staxReader = staxFactory().createXMLEventReader( stream );
		try {
			return unmarshal( staxReader, origin );
		}
		finally {
			try {
				staxReader.close();
			}
			catch ( Exception ignore ) {
			}
		}
	}
	catch ( XMLStreamException e ) {
		throw new MappingException( "Unable to create stax reader", e, origin );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:JaxbProcessor.java

示例7: testCR6419687

import javax.xml.stream.XMLEventReader; //导入依赖的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

示例8: toDom4jDocument

import javax.xml.stream.XMLEventReader; //导入依赖的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

示例9: createXMLEventReader

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
/**
 * Method checks if the storage type is supported and transforms it to XMLEventReader instance which is then returned.
 * Throws PolicyException if the transformation is not succesfull or if the storage type is not supported.
 *
 * @param storage An XMLEventReader instance.
 * @return The storage cast to an XMLEventReader.
 * @throws PolicyException If the XMLEventReader cast failed.
 */
private XMLEventReader createXMLEventReader(final Object storage)
        throws PolicyException {
    if (storage instanceof XMLEventReader) {
        return (XMLEventReader) storage;
    }
    else if (!(storage instanceof Reader)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0022_STORAGE_TYPE_NOT_SUPPORTED(storage.getClass().getName())));
    }

    try {
        return XMLInputFactory.newInstance().createXMLEventReader((Reader) storage);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0014_UNABLE_TO_INSTANTIATE_READER_FOR_STORAGE(), e));
    }

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:XmlPolicyModelUnmarshaller.java

示例10: parse

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
public TubelineFeature parse(XMLEventReader reader) throws WebServiceException {
    try {
        final StartElement element = reader.nextEvent().asStartElement();
        boolean attributeEnabled = true;
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName attributeName = nextAttribute.getName();
            if (ENABLED_ATTRIBUTE_NAME.equals(attributeName)) {
                attributeEnabled = ParserUtil.parseBooleanValue(nextAttribute.getValue());
            } else if (NAME_ATTRIBUTE_NAME.equals(attributeName)) {
                // TODO use name attribute
            } else {
                // TODO logging message
                throw LOGGER.logSevereException(new WebServiceException("Unexpected attribute"));
            }
        }
        return parseFactories(attributeEnabled, element, reader);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:TubelineFeatureReader.java

示例11: eventReaderTest

import javax.xml.stream.XMLEventReader; //导入依赖的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

示例12: getXMLEventReader

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
private XMLEventReader getXMLEventReader(final String filename) {

        XMLInputFactory xmlif = null;
        XMLEventReader xmlr = null;
        try {
            xmlif = XMLInputFactory.newInstance();
            xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
            xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
            xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
            xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);

            // FileInputStream fis = new FileInputStream(filename);
            FileInputStream fis = new FileInputStream(new File(ValidatorTest.class.getResource(filename).toURI()));
            xmlr = xmlif.createXMLEventReader(filename, fis);
        } catch (Exception ex) {
            ex.printStackTrace();
            Assert.fail("Exception : " + ex.getMessage());
        }
        return xmlr;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ValidatorTest.java

示例13: test0

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
@Test
public void test0() {
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();

        XMLStreamReader xsr = xif.createXMLStreamReader(getClass().getResource("sgml.xml").toString(), getClass().getResourceAsStream("sgml.xml"));

        XMLEventReader xer = xif.createXMLEventReader(xsr);

        Assert.assertTrue(xer.peek().getEventType() == XMLEvent.START_DOCUMENT);
        Assert.assertTrue(xer.peek() == xer.nextEvent());
        xsr.close();
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Bug6489890.java

示例14: testUnmarshall

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
/**
 * Test method for GetAttributesResponseUnmarshaller
 */
@Test
public final void testUnmarshall() throws Exception {
    XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
    XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(DomainMetadataResultUnmarshallerTest.class
                                                                              .getResourceAsStream("GetAttributesResponse.xml"));
    StaxUnmarshallerContext unmarshallerContext = new StaxUnmarshallerContext(eventReader);
    GetAttributesResponse result = new GetAttributesResponseUnmarshaller()
            .unmarshall(unmarshallerContext);

    assertTrue(!result.attributes().isEmpty());
    assertTrue(result.attributes().size() == 2);
    assertTrue(result.attributes().get(0).name().equals("Color"));
    assertTrue(result.attributes().get(0).value().equals("Blue"));
    assertTrue(result.attributes().get(1).name().equals("Price"));
    assertTrue(result.attributes().get(1).value().equals("$2.50"));
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:20,代码来源:GetAttributesResultUnmarshallerTest.java

示例15: testXpathUnmarshaller

import javax.xml.stream.XMLEventReader; //导入依赖的package包/类
/**
 * Test method for DomainMetadataResultXpathUnmarshaller
 */
@Test
public final void testXpathUnmarshaller() throws Exception {
    XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
    XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(DomainMetadataResultUnmarshallerTest.class
                                                                              .getResourceAsStream("DomainMetadataResponse.xml"));
    StaxUnmarshallerContext unmarshallerContext = new StaxUnmarshallerContext(eventReader);
    DomainMetadataResponse result = new DomainMetadataResponseUnmarshaller()
            .unmarshall(unmarshallerContext);

    assertTrue(result.itemCount() == 25);
    assertTrue(result.itemNamesSizeBytes() == 12345);
    assertTrue(result.attributeNameCount() == 20);
    assertTrue(result.attributeNamesSizeBytes() == 2345);
    assertTrue(result.attributeValueCount() == 25);
    assertTrue(result.attributeValuesSizeBytes() == 1234);
    assertTrue(result.timestamp() == 5555);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:21,代码来源:DomainMetadataResultUnmarshallerTest.java


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