create Safe Xml Input Factory - Android XML

Android examples for XML:XML Parse

Description

create Safe Xml Input Factory

Demo Code


//package com.java2s;
import javax.xml.stream.XMLInputFactory;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(createSafeXmlInputFactory());
    }/*from   w  ww  .j a v  a2 s. co  m*/

    public static XMLInputFactory createSafeXmlInputFactory() {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        if (xif.isPropertySupported(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES)) {
            xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,
                    false);
        }

        if (xif.isPropertySupported(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES)) {
            xif.setProperty(
                    XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
        }

        if (xif.isPropertySupported(XMLInputFactory.SUPPORT_DTD)) {
            xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        }
        return xif;
    }
}

Related Tutorials