List of usage examples for javax.xml.stream XMLInputFactory newInstance
public static XMLInputFactory newInstance() throws FactoryConfigurationError
From source file:edu.harvard.i2b2.pm.ws.PMServiceDriver.java
/** * Function to convert pm requestVdo to OMElement * //from ww w . j a v a 2s.c o m * @param requestPm String request to send to pm web service * @return An OMElement containing the pm web service requestVdo */ public static OMElement getPmPayLoad(String requestPm) throws Exception { OMElement lineItem = null; try { StringReader strReader = new StringReader(requestPm); XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader reader = xif.createXMLStreamReader(strReader); StAXOMBuilder builder = new StAXOMBuilder(reader); lineItem = builder.getDocumentElement(); } catch (FactoryConfigurationError e) { log.error(e.getMessage()); throw new Exception(e); } return lineItem; }
From source file:com.dulion.astatium.mesh.shredder.XmlShredder.java
public XmlShredder(MetaGraph metaGraph) { this.manager = (ContextManager) metaGraph; this.factory = ThreadLocal.withInitial(() -> { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); return factory; });/*from w w w. ja v a2 s . c o m*/ }
From source file:com.msopentech.odatajclient.testservice.utils.XMLEventReaderWrapper.java
public XMLEventReaderWrapper(final InputStream stream) throws Exception { final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_VALIDATING, false); factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false); this.wrapped = factory.createXMLEventReader(new ByteArrayInputStream( (XMLEventReaderWrapper.CONTENT_STAG + IOUtils.toString(stream) + XMLEventReaderWrapper.CONTENT_ETAG) .getBytes()));/*ww w .ja v a2 s. c o m*/ init(wrapped); }
From source file:StAXEventTreeViewer.java
public void buildTree(DefaultTreeModel treeModel, DefaultMutableTreeNode current, File file) throws XMLStreamException, FileNotFoundException { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLEventReader reader = inputFactory.createXMLEventReader(new FileInputStream(file)); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.START_DOCUMENT: StartDocument startDocument = (StartDocument) event; DefaultMutableTreeNode version = new DefaultMutableTreeNode(startDocument.getVersion()); current.add(version);/* w ww . j a va 2s . c om*/ current.add(new DefaultMutableTreeNode(startDocument.isStandalone())); current.add(new DefaultMutableTreeNode(startDocument.standaloneSet())); current.add(new DefaultMutableTreeNode(startDocument.encodingSet())); current.add(new DefaultMutableTreeNode(startDocument.getCharacterEncodingScheme())); break; case XMLStreamConstants.START_ELEMENT: StartElement startElement = (StartElement) event; QName elementName = startElement.getName(); DefaultMutableTreeNode element = new DefaultMutableTreeNode(elementName.getLocalPart()); current.add(element); current = element; if (!elementName.getNamespaceURI().equals("")) { String prefix = elementName.getPrefix(); if (prefix.equals("")) { prefix = "[None]"; } DefaultMutableTreeNode namespace = new DefaultMutableTreeNode( "prefix=" + prefix + ",URI=" + elementName.getNamespaceURI()); current.add(namespace); } for (Iterator it = startElement.getAttributes(); it.hasNext();) { Attribute attr = (Attribute) it.next(); DefaultMutableTreeNode attribute = new DefaultMutableTreeNode("Attribute (name=" + attr.getName().getLocalPart() + ",value=" + attr.getValue() + "')"); String attURI = attr.getName().getNamespaceURI(); if (!attURI.equals("")) { String attPrefix = attr.getName().getPrefix(); if (attPrefix.equals("")) { attPrefix = "[None]"; } attribute.add(new DefaultMutableTreeNode("prefix = " + attPrefix + ", URI = " + attURI)); } current.add(attribute); } break; case XMLStreamConstants.END_ELEMENT: current = (DefaultMutableTreeNode) current.getParent(); break; case XMLStreamConstants.CHARACTERS: Characters characters = (Characters) event; if (!characters.isIgnorableWhiteSpace() && !characters.isWhiteSpace()) { String data = characters.getData(); if (data.length() != 0) { current.add(new DefaultMutableTreeNode(characters.getData())); } } break; case XMLStreamConstants.DTD: DTD dtde = (DTD) event; current.add(new DefaultMutableTreeNode(dtde.getDocumentTypeDeclaration())); default: System.out.println(event.getClass().getName()); } } }
From source file:edu.cmu.lti.oaqa.knn4qa.collection_reader.YahooAnswersStreamParser.java
public YahooAnswersStreamParser(String fileName, boolean bDoCleanUp) throws IOException, XMLStreamException { mFile = new File(fileName); mDoCleanUp = bDoCleanUp;/*from www .j av a2s. com*/ final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, true); mReader = factory.createXMLStreamReader(CompressUtils.createInputStream(fileName)); mNextDoc = fetchNext(); }
From source file:au.org.ala.bhl.DocumentPaginator.java
public void paginate(Reader reader, PageHandler handler) { XMLInputFactory factory = XMLInputFactory.newInstance(); try {//from w w w .j av a 2s . c o m XMLStreamReader parser = factory.createXMLStreamReader(reader); paginateImpl(parser, handler); } catch (Exception ex) { throw new RuntimeException("Failed to paginate from reader", ex); } }
From source file:net.kados.gtp.app.libs.Teryt.Subjects.Streets.java
@Override public void extract() throws XMLStreamException, FileNotFoundException { FileInfo ulic = this.bfis.get(Parser.Types.ULIC.toString()); this.factory = XMLInputFactory.newInstance(); this.readerRaw = factory .createXMLStreamReader(new BufferedInputStream(new FileInputStream(ulic.getFile()))); this.reader = factory.createFilteredReader(readerRaw, this.newLineFilter); while (reader.hasNext()) { int next = reader.next(); switch (next) { case XMLStreamConstants.START_ELEMENT: this.newElement(reader.getLocalName()); break; case XMLStreamConstants.CHARACTERS: tagContent = reader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: this.endElement(reader.getLocalName()); break; }/*from ww w . j a v a2s. com*/ if (streets.size() >= 1000) { this.save(); } parserMessages.sendProgress(reader.getLocation().getLineNumber(), ulic.getLines()); } this.save(); }
From source file:com.hp.application.automation.tools.octane.tests.TestResultIterator.java
public TestResultIterator(Reader input) throws FileNotFoundException, XMLStreamException { this.input = input; reader = XMLInputFactory.newInstance().createXMLEventReader(input); }
From source file:edu.harvard.i2b2.im.ws.MessageFactory.java
/** * Function creates Workplace response OMElement from xml string * @param xmlString//w ww . ja v a 2s . c om * @return OMElement * @throws XMLStreamException */ public static OMElement createResponseOMElementFromString(String xmlString) throws I2B2Exception { OMElement returnElement = null; try { StringReader strReader = new StringReader(xmlString); XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader reader = xif.createXMLStreamReader(strReader); StAXOMBuilder builder = new StAXOMBuilder(reader); returnElement = builder.getDocumentElement(); } catch (XMLStreamException e) { log.error("xml stream response WDO to OMElement"); throw new I2B2Exception("XML Stream error ", e); } catch (Exception e) { log.error("Error while converting IM response WDO to OMElement"); throw new I2B2Exception("Response OMElement creation error ", e); } return returnElement; }
From source file:com.hp.application.automation.tools.octane.tests.xml.AbstractXmlIterator.java
private static XMLInputFactory createXmlInputFactory() { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); xmlFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); return xmlFactory; }