protected void readFileHeader(XMLStreamReader parser) throws XMLStreamException { int event = parser.getEventType(); while (event != XMLStreamConstants.END_DOCUMENT && parser.getLocalName().equals("osm")) { event = parser.nextTag(); } }
private static void readTags(ReaderElement re, XMLStreamReader parser) throws XMLStreamException { int event = parser.getEventType(); while (event != XMLStreamConstants.END_DOCUMENT && parser.getLocalName().equals("tag")) { if (event == XMLStreamConstants.START_ELEMENT) { // read tag String key = parser.getAttributeValue(null, "k"); String value = parser.getAttributeValue(null, "v"); // ignore tags with empty values if (value != null && value.length() > 0) re.setTag(key, value); } event = parser.nextTag(); } }
public static ReaderNode createNode(long id, XMLStreamReader parser) throws XMLStreamException { ReaderNode node = new ReaderNode(id, Double.parseDouble(parser.getAttributeValue(null, "lat")), Double.parseDouble(parser.getAttributeValue(null, "lon"))); parser.nextTag(); readTags(node, parser); return node; }
private void parseAttribute(final XMLStreamReader streamReader, final Attributes attributes) throws XMLStreamException, RealmUnavailableException { String name = null; String value = null; final int attributeCount = streamReader.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { String namespace = streamReader.getAttributeNamespace(i); if (namespace != null && !namespace.equals("")) { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), this.name); } if ("name".equals(streamReader.getAttributeLocalName(i))) { name = streamReader.getAttributeValue(i); } else if ("value".equals(streamReader.getAttributeLocalName(i))) { value = streamReader.getAttributeValue(i); } else { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), this.name); } } if (name == null) { throw ElytronMessages.log.fileSystemRealmMissingAttribute("name", path, streamReader.getLocation().getLineNumber(), this.name); } if (value == null) { throw ElytronMessages.log.fileSystemRealmMissingAttribute("value", path, streamReader.getLocation().getLineNumber(), this.name); } attributes.addLast(name, value); if (streamReader.nextTag() != END_ELEMENT) { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), this.name); } }
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; }
private LoadedIdentity parseIdentity(final XMLStreamReader streamReader, final boolean skipCredentials, final boolean skipAttributes) throws RealmUnavailableException, XMLStreamException { final int tag = streamReader.nextTag(); if (tag != START_ELEMENT || ! validNamespace(streamReader.getNamespaceURI()) || ! "identity".equals(streamReader.getLocalName())) { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name); } return parseIdentityContents(streamReader, skipCredentials, skipAttributes); }
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()); }
@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(); }
@Test public void partial() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT)); streamReader.nextTag(); // skip to root assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "root"), streamReader.getName()); streamReader.nextTag(); // skip to child assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "child"), streamReader.getName()); StaxStreamXMLReader xmlReader = new StaxStreamXMLReader(streamReader); ContentHandler contentHandler = mock(ContentHandler.class); xmlReader.setContentHandler(contentHandler); xmlReader.parse(new InputSource()); verify(contentHandler).setDocumentLocator(any(Locator.class)); verify(contentHandler).startDocument(); verify(contentHandler).startElement(eq("http://springframework.org/spring-ws"), eq("child"), eq("child"), any(Attributes.class)); verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child"); verify(contentHandler).endDocument(); }
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; }
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()));
resultsBuff.append("\nEdited at line " + delta.getRevised().getPosition() + "\n"); for (Object line : delta.getRevised().getLines()) { String xmlLineEdit = line.toString();//save 'original' xml line into string XMLInputFactory xif = XMLInputFactory.newFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xmlLineEdit));//put xml into parser xsr.nextTag(); // Advance to svg element int attributeCount = xsr.getAttributeCount();//get the number of attributes array1 = new String[attributeCount]; for(int x=0; x<attributeCount; x++) //for each attribute { //StringBuilder stringBuilder = new StringBuilder();//might remove array1[x]= xsr.getAttributeLocalName(x) + "=\"" + xsr.getAttributeValue(x) + "\"";//add attributes and values to an array } Arrays.sort(array1);//sort the array alphabetically
public ApplicationClientMetaData parse(XMLStreamReader reader, PropertyReplacer propertyReplacer) throws XMLStreamException { reader.require(START_DOCUMENT, null, null); // Read until the first start element while (reader.hasNext() && reader.next() != START_ELEMENT) {} final ApplicationClientMetaData appClientMetadata = new ApplicationClientMetaData(); // Handle attributes and set them in the EjbJarMetaData final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (attributeHasNamespace(reader, i)) { continue; } processAttribute(appClientMetadata, reader, i); } appClientMetadata.setDescriptionGroup(new DescriptionGroupMetaData()); appClientMetadata.setEnvironmentRefsGroupMetaData(new AppClientEnvironmentRefsGroupMetaData()); // parse and create metadata out of the elements while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { processElement(appClientMetadata, reader, propertyReplacer); } return appClientMetadata; }
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) { } } }
ConfigModel model = document.getModelByElementName(in.getLocalName()); if(model==null) { String localName = in.getLocalName(); Logger.getAnonymousLogger().severe("Ignoring unrecognized element "+in.getLocalName() + " at " + in.getLocation()); final int tag = in.nextTag(); if (tag==START_ELEMENT && in.getLocalName().equals(localName)) { if (Logger.getAnonymousLogger().isLoggable(Level.FINE)) {
int sequenceNumber = 0; final int attributeCount = streamReader.getAttributeCount(); for (int i = 0; i < attributeCount; i ++) { String namespace = streamReader.getAttributeNamespace(i); if (namespace != null && !namespace.equals("")) { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name); name = streamReader.getAttributeValue(i); } else if ("algorithm".equals(localName)) { algorithm = streamReader.getAttributeValue(i); } else if ("hash".equals(localName)) { hash = CodePointIterator.ofString(streamReader.getAttributeValue(i)).base64Decode(Base64Alphabet.STANDARD, false).drain(); } else if ("seed".equals(localName)) { seed = new String(CodePointIterator.ofString(streamReader.getAttributeValue(i)).base64Decode(Base64Alphabet.STANDARD, false).drain(), StandardCharsets.US_ASCII); sequenceNumber = Integer.parseInt(streamReader.getAttributeValue(i)); } else { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name); if (streamReader.nextTag() != END_ELEMENT) { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name);
@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; }
private Attributes parseAttributes(final XMLStreamReader streamReader) throws RealmUnavailableException, XMLStreamException { final int attributeCount = streamReader.getAttributeCount(); if (attributeCount > 0) { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name); } int tag = streamReader.nextTag(); if (tag == END_ELEMENT) { return Attributes.EMPTY; } Attributes attributes = new MapAttributes(); do { if (! validNamespace(streamReader.getNamespaceURI())) { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name); } if ("attribute".equals(streamReader.getLocalName())) { parseAttribute(streamReader, attributes); } else { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name); } } while (streamReader.nextTag() == START_ELEMENT); return attributes; }