private Attributes getAttributes(StartElement event) { AttributesImpl attributes = new AttributesImpl(); for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); QName qName = attribute.getName(); String namespace = qName.getNamespaceURI(); if (namespace == null || !hasNamespacesFeature()) { type = "CDATA"; attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue()); for (Iterator i = event.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); String prefix = namespace.getPrefix(); String namespaceUri = namespace.getNamespaceURI();
private Attribute mapAttribute(StartElement startElement, Attribute originalAttribute) { // Here we look to see if this attribute is the JPA version attribute, and if so do 2 things: // 1) validate its version attribute is valid // 2) update its version attribute to the default version if not already // // NOTE : atm this is a very simple check using just the attribute's local name // rather than checking its qualified name. It is possibly (though unlikely) // that this could match on "other" version attributes in the same element if ( ROOT_ELEMENT_NAME.equals( startElement.getName().getLocalPart() ) ) { if ( VERSION_ATTRIBUTE_NAME.equals( originalAttribute.getName().getLocalPart() ) ) { final String specifiedVersion = originalAttribute.getValue(); if ( !LocalXsdResolver.isValidJpaVersion( specifiedVersion ) ) { throw new BadVersionException( specifiedVersion ); } return xmlEventFactory.createAttribute( VERSION_ATTRIBUTE_NAME, LocalXsdResolver.latestJpaVerison() ); } } return originalAttribute; }
@Override public Object unmarshal(Source source) throws XmlMappingException, IOException { Attribute attr = null ; try { XMLEventReader eventReader = StaxTestUtils.getXmlEventReader( source); assertTrue(eventReader.nextEvent().isStartDocument()); StartElement event = eventReader.nextEvent().asStartElement(); attr = (Attribute) event.getAttributes().next(); } catch (Exception e) { throw new RuntimeException(e); } Foo foo = new Foo(); foo.setValue(Integer.parseInt(attr.getValue())); return foo; }
private Element copyAttributes(StartElement source, Element destination) { for (Attribute attribute : forwardOnly(Unchecked.<Iterator<Attribute>>cast(source.getAttributes()))) { destination.setAttribute(attribute.getName().getLocalPart(), attribute.getValue()); } return destination; }
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())); }
/** * Constructs a new DOM4J Attribute from the provided StAX Attribute event. * * @param elem * DOCUMENT ME! * @param attr * The Attribute event from which to construct the new DOM4J * Attribute. * * @return The Attribute constructed from the provided Attribute event. */ public org.dom4j.Attribute createAttribute(Element elem, Attribute attr) { return factory.createAttribute(elem, createQName(attr.getName()), attr .getValue()); }
for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute staxAttr = (Attribute)i.next(); QName name = staxAttr.getName(); String uri = fixNull(name.getNamespaceURI()); String localName = name.getLocalPart(); String prefix = name.getPrefix(); String qName; qName = prefix + ':' + localName; String type = staxAttr.getDTDType(); String value = staxAttr.getValue();
@Override public Object unmarshal(Source source) throws XmlMappingException, IOException { Attribute attr; try { XMLEventReader eventReader = StaxTestUtils.getXmlEventReader(source ); assertTrue(eventReader.nextEvent().isStartDocument()); StartElement event = eventReader.nextEvent().asStartElement(); attr = (Attribute) event.getAttributes().next(); } catch ( Exception e) { throw new RuntimeException(e); } Foo foo = new Foo(); foo.setValue(Integer.parseInt(attr.getValue())); return foo; }
private void writeAttribute(Attribute a) throws XMLStreamException { writer.writeAttribute(a.getName().getNamespaceURI(), a.getName().getLocalPart(), a.getValue()); } public void addAttribute(Attribute a)
private Attributes getAttributes(StartElement event) { AttributesImpl attributes = new AttributesImpl(); for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); QName qName = attribute.getName(); String namespace = qName.getNamespaceURI(); if (namespace == null || !hasNamespacesFeature()) { type = "CDATA"; attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue()); for (Iterator i = event.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); String prefix = namespace.getPrefix(); String namespaceUri = namespace.getNamespaceURI();
private static void writeAttributeEvent(XMLEvent event, XMLStreamWriter writer) throws XMLStreamException { Attribute attr = (Attribute)event; QName name = attr.getName(); String nsURI = name.getNamespaceURI(); String localName = name.getLocalPart(); String prefix = name.getPrefix(); String value = attr.getValue(); if (prefix != null) { writer.writeAttribute(prefix, nsURI, localName, value); } else if (nsURI != null) { writer.writeAttribute(nsURI, localName, value); } else { writer.writeAttribute(localName, value); } }
private Object parseUnknownField(StartElement startElement, boolean dropUnknown, RecordSchema schema) throws XMLStreamException { final Iterator iterator = startElement.getAttributes(); while (iterator.hasNext()) { final Attribute attribute = (Attribute) iterator.next(); final String attributeName = attribute.getName().toString(); final Optional<RecordField> field = schema.getField(attributeName); if (field.isPresent()){ recordValues.put(attributePrefix == null ? attributeName : attributePrefix + attributeName, attribute.getValue()); recordValues.put(attributePrefix == null ? attributeName : attributePrefix + attributeName, attribute.getValue()); final String subFieldName = subStartElement.getName().getLocalPart();
private static void printAttribute(Attribute a) { printName(a.getName().getPrefix(),a.getName().getNamespaceURI(), a.getName().getLocalPart()); System.out.print("='"+a.getValue()+"'"); }
final Iterator iterator = startElement.getAttributes(); while (iterator.hasNext()) { final Attribute attribute = (Attribute) iterator.next(); final String attributeName = attribute.getName().toString(); final Object value; final DataType dataType = field.get().getDataType(); if ((value = parseStringForType(attribute.getValue(), attributeName, dataType)) != null) { recordValues.put(targetFieldName, value); recordValues.put(targetFieldName, attribute.getValue()); final Optional<RecordField> field = schema.getField(attributeName); if (field.isPresent()){ if ((value = parseStringForType(attribute.getValue(), attributeName, field.get().getDataType())) != null) { recordValues.put(targetFieldName, value); recordValues.put(targetFieldName, attribute.getValue()); recordValues.put(targetFieldName, attribute.getValue()); final String fieldName = subStartElement.getName().getLocalPart();
private static void printAttribute(Attribute a) { System.out.println("PREFIX: " + a.getName().getPrefix()); System.out.println("NAMESP: " + a.getName().getNamespaceURI()); System.out.println("NAME: " + a.getName().getLocalPart()); System.out.println("VALUE: " + a.getValue()); System.out.println("TYPE: " + a.getDTDType()); }
public void writeStartElement(StartElement elem) throws XMLStreamException { QName name = elem.getName(); writeStartElement(name.getLocalPart()); Iterator it = elem.getAttributes(); while (it.hasNext()) { Attribute attr = (Attribute) it.next(); name = attr.getName(); writeAttribute(name.getLocalPart(), attr.getValue()); } }
public String getAttributeValue(String namespaceURI, String localName) { for (Attribute attribute : getAttributes()) { if (attribute.getName().getNamespaceURI().equals(namespaceURI) && attribute.getName().getLocalPart().equals(localName)) { return attribute.getValue(); } } return null; }
public void writeStartElement(StartElement elem) throws XMLStreamException { /* In repairing mode this is simple: let's just pass info * we have, and things should work... a-may-zing! */ QName name = elem.getName(); writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); Iterator it = elem.getAttributes(); while (it.hasNext()) { Attribute attr = (Attribute) it.next(); name = attr.getName(); writeAttribute(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), attr.getValue()); } }
public String getAttributeValue(String namespaceURI, String localName) { for (Attribute attribute : getAttributes()) { if (attribute.getName().getNamespaceURI().equals(namespaceURI) && attribute.getName().getLocalPart().equals(localName)) { return attribute.getValue(); } } return null; }
protected void outputNsAndAttr(XMLStreamWriter w) throws XMLStreamException { // First namespace declarations, if any: if (mNsCtxt != null) { mNsCtxt.outputNamespaceDeclarations(w); } // Then attributes, if any: if (mAttrs != null && mAttrs.size() > 0) { Iterator it = mAttrs.values().iterator(); while (it.hasNext()) { Attribute attr = (Attribute) it.next(); // Let's only output explicit attribute values: if (!attr.isSpecified()) { continue; } QName name = attr.getName(); String prefix = name.getPrefix(); String ln = name.getLocalPart(); String nsURI = name.getNamespaceURI(); w.writeAttribute(prefix, nsURI, ln, attr.getValue()); } } } }