Java Code Examples for javax.xml.stream.XMLEventReader

Following code examples demonstrate how to use javax.xml.stream.XMLEventReader from java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use javax.xml.stream.XMLEventReader and various code implementation of this class.
Example 1
Project : java Source File : XMLEventReaderClassTests.java View Source Code on GitHub

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to XMLEventReader.class!",
                   XMLEventReader.class.isAssignableFrom(sut));
    }
			
Example 2
Project : java Source File : xsdcomment.java View Source Code on GitHub

	private XMLEventReader processComments(XMLEventWriter writer, Comment comment ) throws XMLStreamException, IOException {
		
		
		String text = comment.getText().trim();
		if( ! text.startsWith("<jxon:"))
			return null ;
		
		
		
		String xml = 
			"<xs:annotation xmlns:xs=\"" + kSCHEMA_NS + "\" xmlns:jxon=\""  + kJXON_NS + "\"> " + 
				"<xs:appinfo>" + 
					text + 
				"</xs:appinfo>" +
			"</xs:annotation>" ;
				
		
		
		InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
		XMLEventReader	reader = new NoDocXMLEventReader( mInputFactory.createXMLEventReader(is));
		
		return reader ;
		
		
	}
			
Example 3
Project : java Source File : xsdcomment.java View Source Code on GitHub

	public int run(List<XValue> args) throws Exception {
		
		Options opts = new Options( SerializeOpts.getOptionDefs() );
		opts.parse(args);
		args = opts.getRemainingArgs();
		
		
		InputPort stdin = null;
		if( args.size() > 0 )
			stdin = getInput( args.get(0));
		else
			stdin = getStdin();
		if( stdin == null )
			throw new InvalidArgumentException("Cannot open input");
		
			
		try {
			
			SerializeOpts sopts = getSerializeOpts(opts);
			
			XMLEventReader	reader = stdin.asXMLEventReader(sopts);
			org.xmlsh.core.io.OutputPort stdout = getStdout();
			XMLEventWriter  writer = stdout.asXMLEventWriter(sopts);
			
			stdout.setSystemId(stdin.getSystemId());
			XMLEvent e;
			
			writer.setPrefix("jxon", kJXON_NS );
			
			XMLEventReader 	commentReader = null ;
			while( reader.hasNext() ){
				e = (XMLEvent) reader.next();
				
				
				if( e.getEventType() == XMLStreamConstants.COMMENT){
					commentReader =  processComments( writer , (Comment) e ) ;
					if( commentReader != null )
						continue ;
				}
				
				
				writer.add(e);
				if( commentReader != null && e.isStartElement()){
					writer.add(commentReader);
					commentReader.close();
					commentReader = null ;
					
				}

			
			}
			reader.close();
			writer.close();
		} 
		finally {
			
			stdin.close();
		}
		return 0;
		
		
	}