Last active
August 29, 2015 14:05
-
-
Save manisnesan/7753b4cc702f8a40d167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sample Method to convert the inputstream feed from GSA to JaxB class Gsafeed | |
*/ | |
public Gsafeed parseRecords(InputStream feedInputStream) { | |
SAXParserFactory spf = SAXParserFactory.newInstance(); | |
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); | |
spf.setFeature("http://xml.org/sax/features/validation", false); | |
spf.setNamespaceAware(true); // Binding attributes | |
EntityResolver entityResolver = new EntityResolver() { | |
@Override | |
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { | |
//To ignore DocType | |
if (publicId.equals("-//Google//DTD GSA Feeds//EN")) { | |
return new InputSource(new StringReader("")); | |
} | |
return null; | |
} | |
}; | |
XMLReader xmlReader = spf.newSAXParser().getXMLReader(); | |
xmlReader.setEntityResolver(entityResolver); | |
SAXSource source = new SAXSource(xmlReader, new InputSource(feedInputStream)); | |
JAXBContext jaxbContext = JAXBContext.newInstance(JAXB-GENERATATED-CLASSES-DIRECTORY); | |
Unmarshaller um = jaxbContext.createUnmarshaller(); | |
gsa = (Gsafeed) um.unmarshal(source); | |
return gsa; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment