XMLInputFactory.setProperty(String name, Object value) : XMLInputFactory « javax.xml.stream « Java by API






XMLInputFactory.setProperty(String name, Object value)

  


import java.io.FileInputStream;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    inputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);

    XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream("e.xml"));
    while (reader.hasNext()) {
      int event = reader.next();
      if (event == XMLStreamConstants.CHARACTERS)
        System.out.println(reader.getText());
      else if (event == XMLStreamConstants.ENTITY_REFERENCE) {
        System.out.println("en: " + reader.getLocalName());
        System.out.println("er: " + reader.getText());
      }
    }
    inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);

    reader = inputFactory.createXMLStreamReader(new FileInputStream("e.xml"));
    while (reader.hasNext()) {
      int event = reader.next();
      if (event == XMLStreamConstants.CHARACTERS)
        System.out.println(reader.getText());
      else if (event == XMLStreamConstants.ENTITY_REFERENCE) {
        System.out.println("en: " + reader.getLocalName());
        System.out.println("er: " + reader.getText());
      }
    }
  }
}

   
    
  








Related examples in the same category

1.XMLInputFactory.IS_COALESCING
2.XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES
3.XMLInputFactory: createFilteredReader(XMLEventReader reader, EventFilter filter)
4.XMLInputFactory: createFilteredReader(XMLStreamReader reader, StreamFilter filter)
5.XMLInputFactory: createXMLEventReader(InputStream stream)
6.XMLInputFactory: createXMLEventReader(Reader reader)
7.XMLInputFactory: createXMLStreamReader(InputStream stream)
8.XMLInputFactory: setXMLResolver(XMLResolver resolver)