XMLInputFactory: setXMLResolver(XMLResolver resolver) : XMLInputFactory « javax.xml.stream « Java by API






XMLInputFactory: setXMLResolver(XMLResolver resolver)

  

import java.io.FileInputStream;

import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLResolver;
import javax.xml.stream.XMLStreamException;

public class Main {
  public static void main(String[] args) throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    inputFactory.setXMLResolver(new XMLResolver() {
      public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace)
          throws XMLStreamException {
        System.out.println(systemID);
        return null;
      }
    });

    XMLEventReader reader = inputFactory.createXMLEventReader(new FileInputStream(
        "dtd.xml"));
    XMLEventWriter writer = XMLOutputFactory.newInstance().createXMLEventWriter(System.out);
    writer.add(reader);
    writer.flush();

  }

}

   
    
  








Related examples in the same category

1.XMLInputFactory.IS_COALESCING
2.XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES
3.XMLInputFactory.setProperty(String name, Object value)
4.XMLInputFactory: createFilteredReader(XMLEventReader reader, EventFilter filter)
5.XMLInputFactory: createFilteredReader(XMLStreamReader reader, StreamFilter filter)
6.XMLInputFactory: createXMLEventReader(InputStream stream)
7.XMLInputFactory: createXMLEventReader(Reader reader)
8.XMLInputFactory: createXMLStreamReader(InputStream stream)