private String getAttributeValue(StartElement event, String name) { String value = null; Attribute attr = event.getAttributeByName(new QName(name)); if (attr != null) { value = attr.getValue(); } return value; }
while (xmlEventReader.hasNext()) { XMLEvent xmlEvent = xmlEventReader.nextEvent(); if (xmlEvent.isStartElement()) { StartElement element = xmlEvent.asStartElement(); if (phase == 3 && element.getName().equals(qNode)) { osmNode = new OSMNode(); osmNode.setId(Long.parseLong(element.getAttributeByName(qId).getValue())); osmNode.lat = Double.parseDouble(element.getAttributeByName(qLat).getValue()); osmNode.lon = Double.parseDouble(element.getAttributeByName(qLon).getValue()); } else if (phase == 2 && element.getName().equals(qWay)) { osmWay = new OSMWay(); osmWay.setId(Long.parseLong(element.getAttributeByName(qId).getValue())); } else if (phase == 1 && element.getName().equals(qRelation)) { osmRelation = new OSMRelation(); osmRelation.setId(Long.parseLong(element.getAttributeByName(qId).getValue())); relMember.setType(element.getAttributeByName(qType).getValue()); relMember.setRole(element.getAttributeByName(qRole).getValue()); relMember.setRef(Long.parseLong(element.getAttributeByName(qRef).getValue())); osmRelation.addMember(relMember); nodeRef.setRef(Long.parseLong(element.getAttributeByName(qRef).getValue())); osmWay.addNodeRef(nodeRef); String key = element.getAttributeByName(qKey).getValue(); tag.setK(key.intern()); String value = element.getAttributeByName(qVal).getValue();
List<String> heldComments = new ArrayList<String>(1); while (streamReader.hasNext()) { XMLEvent nextEvent = streamReader.nextEvent(); try { StartElement elem = nextEvent.asStartElement(); String namespaceURI = elem.getName().getNamespaceURI(); if ("extension".equals(elem.getName().getLocalPart())) { Attribute urlAttr = elem.getAttributeByName(new QName("url")); String url; if (urlAttr == null || isBlank(urlAttr.getValue())) { } else if ("modifierExtension".equals(elem.getName().getLocalPart())) { Attribute urlAttr = elem.getAttributeByName(new QName("url")); String url; if (urlAttr == null || isBlank(urlAttr.getValue())) {
/** * Get the Attribute value * * @param startElement * @param tag localpart of the qname of the attribute * @return */ public static String getAttributeValue(StartElement startElement, String tag) { String result = null; Attribute attr = startElement.getAttributeByName(new QName(tag)); if (attr != null) result = getAttributeValue(attr); return result; }
private ObjectPair<String, IVersion> process(final StartElement element) { final QName attributeName = new QName(VERSION); final Attribute attribute = element.getAttributeByName(attributeName); return new ObjectPair<>( element.getName().getLocalPart(), attribute == null ? null : convertToVersion(attribute.getValue())); }
private XMLEvent rewriteNameAttribute(XMLEvent e) { String value = e.asStartElement().getAttributeByName(new QName(NAME)).getValue(); String translatedSharedString = sharedStrings.get(value); if (translatedSharedString == null) { return e; } else { Attribute attr = eventFactory.createAttribute(NAME, translatedSharedString); Iterator attributeIterator = e.asStartElement().getAttributes(); ArrayList<Attribute> updatedAttributes = new ArrayList<>(); while (attributeIterator.hasNext()) { Attribute attribute = (Attribute) attributeIterator.next(); if (NAME.equalsIgnoreCase(attribute.getName().toString())) { updatedAttributes.add(attr); } else { updatedAttributes.add(attribute); } } return eventFactory.createStartElement(e.asStartElement().getName(), updatedAttributes.iterator(), e.asStartElement().getNamespaces()); } }
private Property property(final XMLEventReader reader, final StartElement start) throws XMLStreamException, EdmPrimitiveTypeException { final Property property = new Property(); if (propertyValueQName.equals(start.getName())) { // retrieve name from context final Attribute context = start.getAttributeByName(contextQName); if (context != null) { property.setName(StringUtils.substringAfterLast(context.getValue(), "/")); } } else { property.setName(start.getName().getLocalPart()); } valuable(property, reader, start); return property; }
public static List<String> getXSDs(String wsdl) throws XMLStreamException { List<String> result = new ArrayList<String>(); XMLEventReader parser; synchronized(xmlInputFactory) { parser = xmlInputFactory.createXMLEventReader(new StringReader(wsdl)); } while (parser.hasNext()) { XMLEvent event = parser.nextEvent(); if (event.isStartElement()) { String name = event.asStartElement().getName().getLocalPart(); if (name.equals("import") || name.equals("include")) { Attribute a = event.asStartElement().getAttributeByName(new QName("schemaLocation")); if (a != null) result.add(a.getValue()); } } } return result; }
/** * Get the Attribute value * * @param startElement * @param tag localpart of the qname of the attribute * * @return */ public static String getAttributeValue(StartElement startElement, String tag) { String result = null; Attribute attr = startElement.getAttributeByName(new QName(tag)); if (attr != null) result = getAttributeValue(attr); return result; }
private String getAttribute(StartElement element, String name) { Attribute att = element.getAttributeByName(new QName(name)); return (att != null) ? att.getValue() : null; } private long parseTime(DatatypeFactory dtFactory, Calendar now, String time) {
/** * Extract a link from the input stream. This should be an empty element * * @param se * the start element * @return an atom link element * @throws MalformedURLException * @throws XMLStreamException */ private AtomLink parseLink(StartElement se) throws MalformedURLException, XMLStreamException { Attribute rel = se.getAttributeByName(new QName("rel")); Attribute href = se.getAttributeByName(new QName("href")); XMLEvent ev = stream.nextEvent(); while (ev != null) { if (foundEndTag(ev, se.getName())) break; ev = stream.nextEvent(); } return new AtomLink(new URL(href.getValue()), rel != null ? rel.getValue() : null); }
private String entityRef(final XMLEventReader reader, final StartElement start) throws XMLStreamException { boolean foundEndElement = false; final Attribute entityRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID); while (reader.hasNext() && !foundEndElement) { final XMLEvent event = reader.nextEvent(); if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndElement = true; } } return entityRefId.getValue(); }
private Property property(final XMLEventReader reader, final StartElement start) throws XMLStreamException, EdmPrimitiveTypeException { final Property property = new Property(); if (propertyValueQName.equals(start.getName())) { // retrieve name from context final Attribute context = start.getAttributeByName(contextQName); if (context != null) { property.setName(StringUtils.substringAfterLast(context.getValue(), "/")); } } else { property.setName(start.getName().getLocalPart()); } valuable(property, reader, start); return property; }
public boolean hasNext() throws XMLStreamException { this.nextBeingCalled = true; if (this.finalized) { // we finished already - no more to read return false; } if ((this.currentRow > 1) && (this.currentRow <= this.nextRow)) { // we still have to process an empty row return true; } // search for the next row while (this.xer.hasNext()) { XMLEvent xe = xer.nextEvent(); if (xe.isStartElement() && xe.asStartElement().getName().getLocalPart().equalsIgnoreCase("row")) { // we // found // a row // get row number. Attribute at = xe.asStartElement().getAttributeByName(new QName("r")); String atValue = at.getValue(); this.nextRow = Integer.valueOf(atValue); return true; } } this.finalized = true; return false; }
/** * Get the Attribute value * * @param startElement * @param tag localpart of the qname of the attribute * * @return */ public static String getAttributeValue(StartElement startElement, String tag) { String result = null; Attribute attr = startElement.getAttributeByName(new QName(tag)); if (attr != null) result = getAttributeValue(attr); return result; }
private static String attr(StartElement element, String name) { Attribute attr = element.getAttributeByName(new QName(name)); if (attr != null) { return attr.getValue(); } return null; }
@SuppressWarnings("unchecked") private void parseEntity(JoinTables joinTables, ParseSession status, XMLEvent event) throws XMLStreamException, InstantiationException, IllegalAccessException, ClassNotFoundException, ImportException { StartElement element = event.asStartElement(); Attribute attribute = element.getAttributeByName(new QName("CLASS")); if (attribute != null) { try { String aClass = attribute.getValue(); Class<? extends DomainObject> doClass = (Class<? extends DomainObject>) Class.forName(aClass); entityParser.parse(doClass, joinTables, status); } catch (Exception e) { LOG.warn("element " + attribute.getValue() + " threw " + e.getMessage(), e); throw new ImportException("element " + attribute.getValue() + " threw " + e.getMessage(), e); } } else { throw new ImportException("Invalid XML, no attribute found for element: " + element.getName().getLocalPart()); } } }
private String entityRef(final XMLEventReader reader, final StartElement start) throws XMLStreamException { boolean foundEndElement = false; final Attribute entityRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID); while (reader.hasNext() && !foundEndElement) { final XMLEvent event = reader.nextEvent(); if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndElement = true; } } return entityRefId.getValue(); }
/** * This checks that not only is the element a break element, but also * that it's a true "line" break, not a page or column break. */ static boolean isLineBreakStartEvent(XMLEvent e) { if (isStartElement(e, LOCAL_BREAK) || isStartElement(e, LOCAL_CARRIAGE_RETURN)) { StartElement start = e.asStartElement(); QName typeName = createQName(LOCAL_TYPE, start.getName()); Attribute a = start.getAttributeByName(typeName); if (a == null) { return true; } String type = a.getValue(); if (!type.equals("page") && !type.equals("column")) { return true; } } return false; }
private void parseColumnNames() throws XMLStreamException { List<String> columnList = new LinkedList<String>(); while (xmlEventReader != null && xmlEventReader.hasNext()) { XMLEvent xmlEvent = xmlEventReader.nextTag(); if (xmlEvent.isStartElement()) { StartElement startElement = xmlEvent.asStartElement(); if (startElement.getName().getLocalPart().equals("Column")) { StartElement columnElement = xmlEvent.asStartElement(); Attribute nameAttr = columnElement.getAttributeByName(new QName("name")); columnList.add(nameAttr.getValue()); } else if (startElement.getName().getLocalPart().equals("Table")) { if (columnList.size() > 0) { // in case there is no columns names - ExcludeColumnHeader is set to true. String[] columns = new String[columnList.size()]; columnList.toArray(columns); reportHeader.setReportColumns(columns); } break; } } } } }