Package javax.xml.stream.events

Examples of javax.xml.stream.events.StartDocument


            int type = nextEvent.getEventType();

            switch (type) {
                case XMLStreamConstants.START_DOCUMENT:

                    StartDocument event = (StartDocument) reader.nextEvent();

                    if (doc == null) {
                        // create document
                        if (event.encodingSet()) {
                            String encodingScheme = event
                                    .getCharacterEncodingScheme();
                            doc = factory.createDocument(encodingScheme);
                        } else {
                            doc = factory.createDocument();
                        }
                    } else {
                        // duplicate or misplaced xml declaration
                        String msg = "Unexpected StartDocument event";
                        throw new XMLStreamException(msg, event.getLocation());
                    }

                    break;

                case XMLStreamConstants.END_DOCUMENT:
View Full Code Here


            rdr = xmlInputFactory.createXMLEventReader(
                    new InputStreamReader(is));
            while (rdr.hasNext()) {
                final XMLEvent ev = rdr.nextEvent();
                if (ev.isStartDocument()) {
                    final StartDocument sd = (StartDocument) ev;
                    encoding = sd.getCharacterEncodingScheme();
                    break;
                }
            }
        } catch (XMLStreamException e) {
            if (rdr != null) {
View Full Code Here

/* 235 */       int type = nextEvent.getEventType();
/*     */
/* 237 */       switch (type)
/*     */       {
/*     */       case 7:
/* 240 */         StartDocument event = (StartDocument)reader.nextEvent();
/*     */
/* 242 */         if (doc == null)
/*     */         {
/* 244 */           if (event.encodingSet()) {
/* 245 */             String encodingScheme = event.getCharacterEncodingScheme();
/*     */
/* 247 */             doc = this.factory.createDocument(encodingScheme);
/*     */           } else {
/* 249 */             doc = this.factory.createDocument();
/*     */           }
/*     */         }
/*     */         else {
/* 253 */           String msg = "Unexpected StartDocument event";
/* 254 */           throw new XMLStreamException(msg, event.getLocation());
/*     */         }
/*     */
/*     */       case 4:
/*     */       case 6:
/*     */       case 8:
View Full Code Here

  }
 
  @Test
  public void testStartEndDocument() throws XMLStreamException {
    XMLStreamReader reader = createXmlStreamReader("<? xml ?>");
    StartDocument startDocument = (StartDocument)eventAllocator.allocate(reader);
    verify(startDocument, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.0\"?>");
    Assert.assertEquals("UTF-8", startDocument.getCharacterEncodingScheme());
    Assert.assertFalse(startDocument.encodingSet());
    Assert.assertEquals("1.0", startDocument.getVersion());
    Assert.assertFalse(startDocument.isStandalone());
    Assert.assertFalse(startDocument.standaloneSet());
    reader.next();
    verify((EndDocument)eventAllocator.allocate(reader), XMLStreamConstants.END_DOCUMENT, "");

    reader = createXmlStreamReader("<? xml version=\"1.1\" ?>");
    startDocument = (StartDocument)eventAllocator.allocate(reader);
    Assert.assertEquals("1.1", startDocument.getVersion());
   
    reader = createXmlStreamReader("<? xml encoding=\"UTF-16\"?>");
    startDocument = (StartDocument)eventAllocator.allocate(reader);
    Assert.assertEquals("UTF-16", startDocument.getCharacterEncodingScheme());
    Assert.assertTrue(startDocument.encodingSet());
  }
View Full Code Here

    case XMLStreamConstants.NAMESPACE:
      Namespace namespace = (Namespace) event;
      delegate.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
      break;
    case XMLStreamConstants.START_DOCUMENT:
      StartDocument startDocument = (StartDocument) event;
      if (startDocument.encodingSet()) { // encoding defined?
        delegate.writeStartDocument(startDocument.getCharacterEncodingScheme(), startDocument.getVersion());
      } else {
        delegate.writeStartDocument(startDocument.getVersion());
      }
      break;
    case XMLStreamConstants.START_ELEMENT:
      StartElement startElement = event.asStartElement();
      QName elemName = startElement.getName();
View Full Code Here

    Assert.assertTrue(event.isIgnorableWhiteSpace());
  }

  @Test
  public void testCreateStartDocument() throws XMLStreamException {
    StartDocument event = factory.createStartDocument();
    verify(event, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.0\"?>");
  }
View Full Code Here

    verify(event, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.0\"?>");
  }

  @Test
  public void testCreateStartDocument_Encoding_Version_Standalone() throws XMLStreamException {
    StartDocument event = factory.createStartDocument("UTF-8", "1.1", true);
    verify(event, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.1\" encoding=\"UTF-8\" standalone=\"yes\"?>");
  }
View Full Code Here

    verify(event, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.1\" encoding=\"UTF-8\" standalone=\"yes\"?>");
  }

  @Test
  public void testCreateStartDocument_Encoding_Version() throws XMLStreamException {
    StartDocument event = factory.createStartDocument("UTF-8", "1.1");
    verify(event, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.1\" encoding=\"UTF-8\"?>");
  }
View Full Code Here

    verify(event, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.1\" encoding=\"UTF-8\"?>");
  }

  @Test
  public void testCreateStartDocument_Encoding() throws XMLStreamException {
    StartDocument event = factory.createStartDocument("UTF-8");
    verify(event, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  }
View Full Code Here

    XMLEventFactory eventFactory = XMLEventFactory.newInstance();
   
    //XMLEvent end = eventFactory.createDTD("\n");
   
    // Create and write Start Tag
    StartDocument startDocument = eventFactory.createStartDocument();
    eventWriter.add(startDocument);

    // Create config open tag
    StartElement configStartElement = eventFactory.createStartElement("","", "config");
    eventWriter.add(configStartElement);
View Full Code Here

TOP

Related Classes of javax.xml.stream.events.StartDocument

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.