FileInputStream fis = null; try { fis = new FileInputStream("test.xml"); XMLInputFactory xmlInFact = XMLInputFactory.newInstance(); XMLStreamReader reader = xmlInFact.createXMLStreamReader(fis); while(reader.hasNext()) { reader.next(); // do something here } } catch(IOException exc) { } catch(XMLStreamException exc) { }
public static String moveDown(XMLStreamReader xtr) { try { while (xtr.hasNext()) { int event = xtr.next(); switch (event) { case XMLStreamConstants.END_DOCUMENT: return null; case XMLStreamConstants.START_ELEMENT: return xtr.getLocalName(); case XMLStreamConstants.END_ELEMENT: return null; } } } catch (Exception e) { LOGGER.warn("Error while moving down in XML document", e); } return null; }
private String getJndiNameFromPersistenceXml() throws XMLStreamException { XMLInputFactory factory = XMLInputFactory.newInstance(); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/persistence.xml"); XMLStreamReader reader = factory.createXMLStreamReader(is); while (reader.hasNext()) { int event = reader.next(); if (event == XMLStreamConstants.START_ELEMENT && "jta-data-source".equals(reader.getLocalName())) { return reader.getElementText(); } } return null; } }
@Override public XResource nextResource() { try { while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { Element element = Element.forName(reader.getLocalName()); switch (element) { case RESOURCE: { return readResourceElement(reader); } } } } catch (XMLStreamException ex) { throw MESSAGES.cannotReadResourceElement(ex, reader.getLocation()); } return null; }
XMLStreamWriter writer = factory.createXMLStreamWriter(stringWriter); while ( reader.hasNext() ) { int event = reader.next(); if (reader.getLocalName().equals("ins")) else if (reader.getLocalName().equals("del")) if (memory.equals(reader.getLocalName())) writer.writeStartElement(reader.getPrefix(), reader.getLocalName(), reader.getNamespaceURI()); for (int i=0; i<reader.getAttributeCount() ; i++ ) { reader.getAttributeValue(i) ); } else { writer.writeAttribute( reader.getAttributeNamespace(i), reader.getAttributeLocalName(i), reader.getAttributeValue(i));
private static void parseNoContent(final XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { return; } default: { throw unexpectedContent(reader); } } } throw endOfDocument(reader.getLocation()); }
private static Set<String> parseSet(final XMLStreamReader reader) throws XMLStreamException { final Set<String> set = new HashSet<String>(); // xsd:choice while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { return set; } case START_ELEMENT: { switch (Element.of(reader.getName())) { case PATH: parsePathName(reader, set); break; } } } } return set; }
@Test public void readStAXSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); StAXSource result = (StAXSource) converter.read(StAXSource.class, inputMessage); XMLStreamReader streamReader = result.getXMLStreamReader(); assertTrue(streamReader.hasNext()); streamReader.nextTag(); String s = streamReader.getLocalName(); assertEquals("root", s); s = streamReader.getElementText(); assertEquals("Hello World", s); streamReader.close(); }
XMLStreamReader vReader = vFactory.createXMLStreamReader( stringReader ); for ( int event = vReader.next(); vReader.hasNext(); event = vReader.next() ) { switch ( event ) { case XMLStreamConstants.START_ELEMENT: logRowlevel( "START_ELEMENT / " + vReader.getAttributeCount() + " / " + vReader.getNamespaceCount() ); logRowlevel( "vReader.getLocalName = " + vReader.getLocalName() ); WebServiceField field = meta.getFieldOutFromWsName( vReader.getLocalName(), ignoreNamespacePrefix ); if ( field != null ) { outputRowData[ outputIndex++ ] = getValue( vReader.getElementText(), field ); oneValueRowProcessing = false; } else { if ( meta.getOutFieldContainerName().equals( vReader.getLocalName() ) ) {
@SuppressWarnings("unchecked") protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception { ExtensionElement extensionElement = new ExtensionElement(); extensionElement.setName(xtr.getLocalName()); if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) { extensionElement.setNamespace(xtr.getNamespaceURI()); } if (StringUtils.isNotEmpty(xtr.getPrefix())) { extensionElement.setNamespacePrefix(xtr.getPrefix()); } BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes); boolean readyWithExtensionElement = false; while (!readyWithExtensionElement && xtr.hasNext()) { xtr.next(); if (xtr.isCharacters() || XMLStreamReader.CDATA == xtr.getEventType()) { if (StringUtils.isNotEmpty(xtr.getText().trim())) { extensionElement.setElementText(xtr.getText().trim()); } } else if (xtr.isStartElement()) { ExtensionElement childExtensionElement = parseExtensionElement(xtr); extensionElement.addChildElement(childExtensionElement); } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) { readyWithExtensionElement = true; } } return extensionElement; }
private static boolean _containsStagedModel( PortletDataContext portletDataContext, String path, StagedModel stagedModel) { XMLInputFactory xmlInputFactory = SecureXMLFactoryProviderUtil.newXMLInputFactory(); try { XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader( portletDataContext.getZipEntryAsInputStream(path)); Class<?> modelClass = stagedModel.getModelClass(); String simpleName = modelClass.getSimpleName(); while (xmlStreamReader.hasNext()) { int event = xmlStreamReader.next(); if (event == XMLStreamConstants.START_ELEMENT) { QName qName = xmlStreamReader.getName(); if (Objects.equals(qName.getLocalPart(), simpleName)) { return true; } } } } catch (XMLStreamException xmlse) { if (_log.isDebugEnabled()) { _log.debug(xmlse, xmlse); } } return false; }
public class Main { public static void main(String args[]) { try{ String raw = "<?xml version='1.0' encoding='iso-8859-1'?><ResDoc><resume canonversion='2' dateversion='2' present='735453' xml:space='preserve'>Jack - A Web ResumeHello,My name is Jack.<statements><personal>This website is all about my career, work experience and skill set. Unlike a traditional resume (available here in Word and PDF) my Web Resume is interactive. Feel free to run a query, a great way to see if I would be a good fit for you and your company, or click on any of the blue links for more details and work samples.Just like my career and capabilities, this site is always growing as I add more examples of my work, and even some blog entries or documentation/ tutorials. You will see this site grow as I do!</personal></statements>I want to thank you for stopping by!Resume<experience>Current employer\t2013\tCurrent\t<title>Systems Administrator</title>\t<description>Windows & Altiris administration, SEP & Credant Encryption Management and Policies,EMR Software Dev company\t2012\t2013\tHelpesk Technician II\tOffice 365,Data-Center migration, Corporate image creation\\ configuration, Domain administrationCommunications\t2011\t2012\tSr. Helpesk Technician\tPrimarily managed IT support issues, requests and tickets from local station & east coast.</description><job id='1'><employer>University\t2008</employer>\t2011\t<title>Desktop Technician/ Analyst\tDesktop Support</title>, <description>managing tickets & walk-ins. I.T. support for professors & faculty..</description></job><job id='2'><employer>Emergence Enterprises LLC</employer>\t2006\t<description>2008\tManaging Member & Technology Consultant\t1099 Contractor in City1 and City 2 areas. Computer consultation and support.Hightlights of IT Skills Don't be shy! Please, click the links for work samples!Technical Support\tSystems Deployment Configuration & Upgrading\tScripting packaging and AutomationPowerShell\tVBScript\tBatchAutoIT\tSQL\tSymantec Management Platform AdministrationPatches & Updates\tTraining & Mentoring\tAV management and deploymentVPN\tProxy and Firewall\tDisk Encryption policy and deploymentLAN/WAN Administration\tInventory Solutions\tand More!</description></job></experience>ReferencesRef_1\tSystems Engineer II\tnationwide companyRef_2\tTechnology & Systems Manager\tUniversityRef_3\tInfrastructure Project Manager\tLocal company</resume><skillrollup version='1'> <canonskill experience='1' expidrefs='2' idrefs='2' name='automation'> <variant>Automation</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='consulting'> <variant>Consultant</variant> <variant>consultation</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='cryptography'> <variant>Encryption</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='firewalls'> <variant>Firewall</variant> </canonskill> <canonskill experience='1' name='imaging'> <variant>image</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='inventory management'> <variant>Inventory</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='lan'> <variant>LAN</variant> </canonskill> <canonskill experience='1' expidrefs='1,2' idrefs='1,2' name='management'> <variant>Managing</variant> <variant>managing</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='mentoring'> <variant>Mentoring</variant> </canonskill> <canonskill experience='1' name='microsoft office'> <variant>Office</variant> </canonskill> <canonskill experience='1' name='microsoft windows'> <variant>Windows</variant> </canonskill> <canonskill experience='1' name='migration'> <variant>migration</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='packaging'> <variant>packaging</variant> </canonskill> <canonskill experience='1' name='policy analysis'> <variant>Policies</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='proxy server'> <variant>Proxy</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='shell scripting'> <variant>Scripting</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='sql'> <variant>SQL</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='symantec packages'> <variant>Symantec</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='technical support'> <variant>Technical Support</variant> </canonskill> <canonskill experience='1' name='technician'> <variant>Technician</variant> <variant>Technician II</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='upgrades'> <variant>Upgrading</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='vbscript'> <variant>VBScript</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='vpn'> <variant>VPN</variant> </canonskill> <canonskill experience='1' expidrefs='2' idrefs='2' name='wan'> <variant>WAN</variant> </canonskill></skillrollup></ResDoc>"; XMLInputFactory xif = XMLInputFactory.newFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(raw)); while(xsr.hasNext()){ xsr.nextTag(); System.out.println(xsr.getName()); System.out.println(xsr.getAttributeCount()); } } catch(XMLStreamException e) { } } }
@Override public void handle(XMLStreamReader xmlr, XMLStreamWriter xmlWriter) throws LocationAwareXMLStreamException, XMLStreamException { while (xmlr.hasNext()) { try { write(xmlr, xmlWriter); } catch (XMLStreamException xse) { // System.out.println("line: " + xmlr.getLocation().getLineNumber()); // System.out.println("col: " + xmlr.getLocation().getColumnNumber()); throw new LocationAwareXMLStreamException(xse.getMessage(), xse, xmlr.getLocation()); } xmlr.next(); } }
private void readDirectiveElement(XMLStreamReader reader, Map<String, String> directives) throws XMLStreamException { String name = reader.getAttributeValue(null, Attribute.NAME.toString()); String value = reader.getAttributeValue(null, Attribute.VALUE.toString()); directives.put(name, value); while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { } } }
WorkManagerSecurity security = null; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.WORKMANAGER) { return new WorkManagerImpl(security); } else { if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
protected static void processResource(final XMLStreamReader reader, final Set<String> resources) throws XMLStreamException { final int attributeCount = reader.getAttributeCount(); if (attributeCount != 1) { throw new XMLStreamException(); } final String path = reader.getAttributeValue(0); resources.add(path.trim()); if (reader.hasNext() && reader.nextTag() != END_ELEMENT) { throw new XMLStreamException("unexpected element"); } }
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception { String id = xtr.getAttributeValue(null, ATTRIBUTE_DI_BPMNELEMENT); GraphicInfo graphicInfo = new GraphicInfo(); String strIsExpanded = xtr.getAttributeValue(null, ATTRIBUTE_DI_IS_EXPANDED); if ("true".equalsIgnoreCase(strIsExpanded)) { graphicInfo.setExpanded(true); } BpmnXMLUtil.addXMLLocation(graphicInfo, xtr); while (xtr.hasNext()) { xtr.next(); if (xtr.isStartElement() && ELEMENT_DI_BOUNDS.equalsIgnoreCase(xtr.getLocalName())) { graphicInfo.setX(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_X))); graphicInfo.setY(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y))); graphicInfo.setWidth(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_WIDTH))); graphicInfo.setHeight(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_HEIGHT))); model.addGraphicInfo(id, graphicInfo); break; } else if (xtr.isEndElement() && ELEMENT_DI_SHAPE.equalsIgnoreCase(xtr.getLocalName())) { break; } } }
public static PlanNode fromXml(String planString) throws XMLStreamException { XMLInputFactory inputFactory = XMLType.getXmlInputFactory(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(planString)); while (reader.hasNext()&& (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) { String element = reader.getLocalName(); if (element.equals("node")) { //$NON-NLS-1$ Properties props = getAttributes(reader); PlanNode planNode = new PlanNode(props.getProperty("name"));//$NON-NLS-1$ planNode.setParent(null); buildNode(reader, planNode); return planNode; } throw new XMLStreamException(JDBCPlugin.Util.gs("unexpected_element", reader.getName(), "node"),reader.getLocation());//$NON-NLS-1$ //$NON-NLS-2$ } return null; }