Java Code Examples for javax.xml.stream.XMLStreamReader#getAttributePrefix()

The following examples show how to use javax.xml.stream.XMLStreamReader#getAttributePrefix() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLSupport.java    From FHIR with Apache License 2.0 6 votes vote down vote up
private static void writeAttributes(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String prefix = reader.getAttributePrefix(i);
        String namespaceURI = reader.getAttributeNamespace(i);
        String localName = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);
        if (namespaceURI != null) {
            if (prefix != null) {
                writer.writeAttribute(prefix, namespaceURI, localName, value);
            } else {
                writer.writeAttribute(namespaceURI, localName, value);
            }
        } else {
            writer.writeAttribute(localName, value);
        }
    }
}
 
Example 2
Source File: Event.java    From jlibs with Apache License 2.0 6 votes vote down vote up
public void onAttributes(XMLStreamReader reader){
    if(interestedInAttributes){
        int len = reader.getAttributeCount();
        for(int i=0; i<len; i++){
            String prefix = reader.getAttributePrefix(i);
            String localName = reader.getAttributeLocalName(i);
            String qname = prefix.length()==0 ? localName : prefix+':'+localName;
            String uri = reader.getAttributeNamespace(i);
            if(uri==null)
                uri = "";
            onEvent(NodeType.ATTRIBUTE, uri, localName, qname, reader.getAttributeValue(i));
            notifyXMLBuilder();
        }
        fireEndAttributes();
    }else if(xmlBuilder!=null && xmlBuilder.active) {
        xmlBuilder.onAttributes(this, reader);
        fireEndAttributes();
    }
}
 
Example 3
Source File: DomReader.java    From cosmo with Apache License 2.0 6 votes vote down vote up
private static Attr readAttribute(int i, Document d, XMLStreamReader reader) throws XMLStreamException {
    Attr a = null;

    String local = reader.getAttributeLocalName(i);
    String ns = reader.getAttributeNamespace(i);
    if (ns != null && !ns.equals("")) {
        String prefix = reader.getAttributePrefix(i);
        String qualified = prefix != null ? prefix + ":" + local : local;
        a = d.createAttributeNS(ns, qualified);
    } else {
        a = d.createAttribute(reader.getAttributeLocalName(i));
    }
    a.setValue(reader.getAttributeValue(i));

    return a;
}
 
Example 4
Source File: XMLBuilder.java    From jlibs with Apache License 2.0 5 votes vote down vote up
public void onAttributes(Event event, XMLStreamReader reader){
    assert active;
    int len = reader.getAttributeCount();
    for(int i=0; i<len; i++){
        String prefix = reader.getAttributePrefix(i);
        String localName = reader.getAttributeLocalName(i);
        String qname = prefix.length()==0 ? localName : prefix+':'+localName;
        String uri = reader.getAttributeNamespace(i);
        if(uri==null)
            uri = "";
        event.setData(NodeType.ATTRIBUTE, uri, localName, qname, reader.getAttributeValue(i));
        onEvent(event);
    }
}
 
Example 5
Source File: StreamWriterFacade.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private void forwardAttributes(final XMLStreamReader reader) throws XMLStreamException {
    for (int i = 0, count = reader.getAttributeCount(); i < count; ++i) {
        final String localName = reader.getAttributeLocalName(i);
        final String value = reader.getAttributeValue(i);
        final String prefix = reader.getAttributePrefix(i);
        if (prefix != null) {
            writer.writeAttribute(prefix, reader.getAttributeNamespace(i), localName, value);
        } else {
            writer.writeAttribute(localName, value);
        }
    }
}
 
Example 6
Source File: XmlFormatter.java    From hop with Apache License 2.0 4 votes vote down vote up
public AttrBuffer( XMLStreamReader rd, int attrIndex ) {
  prefix = rd.getAttributePrefix( attrIndex );
  namespace = rd.getAttributeNamespace( attrIndex );
  localName = rd.getAttributeLocalName( attrIndex );
  value = rd.getAttributeValue( attrIndex );
}
 
Example 7
Source File: XMLFormatter.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public AttrBuffer( XMLStreamReader rd, int attrIndex ) {
  prefix = rd.getAttributePrefix( attrIndex );
  namespace = rd.getAttributeNamespace( attrIndex );
  localName = rd.getAttributeLocalName( attrIndex );
  value = rd.getAttributeValue( attrIndex );
}