Java Code Examples for javax.xml.stream.events.XMLEvent#ATTRIBUTE
The following examples show how to use
javax.xml.stream.events.XMLEvent#ATTRIBUTE .
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: XMLStreamReaderImpl.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * @param namespaceURI * @param localName * @return */ public String getAttributeValue(String namespaceURI, String localName) { //State should be either START_ELEMENT or ATTRIBUTE if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { XMLAttributesImpl attributes = fScanner.getAttributeIterator(); if (namespaceURI == null) { //sjsxp issue 70 return attributes.getValue(attributes.getIndexByLocalName(localName)); } else { return fScanner.getAttributeIterator().getValue( namespaceURI.length() == 0 ? null : namespaceURI, localName); } } else { throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeValue()"); } }
Example 2
Source File: XMLStreamReaderImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** Returns a boolean which indicates if this * attribute was created by default * @param index the position of the attribute * @return true if this is a default attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public boolean isAttributeSpecified(int index) { //check that current state should be either START_ELEMENT or ATTRIBUTE if( (fEventType == XMLEvent.START_ELEMENT) || (fEventType == XMLEvent.ATTRIBUTE)){ return fScanner.getAttributeIterator().isSpecified(index) ; } else{ throw new IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for isAttributeSpecified()") ; } }
Example 3
Source File: XMLStreamReaderImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Returns the prefix of this attribute at the provided index * * @param index the position of the attribute * @return the prefix of the attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public String getAttributePrefix(int index) { //State should be either START_ELEMENT or ATTRIBUTE if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return fScanner.getAttributeIterator().getPrefix(index); } else { throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributePrefix()"); } }
Example 4
Source File: XMLStreamReaderImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
final static String getEventTypeString(int eventType) { switch (eventType){ case XMLEvent.START_ELEMENT: return "START_ELEMENT"; case XMLEvent.END_ELEMENT: return "END_ELEMENT"; case XMLEvent.PROCESSING_INSTRUCTION: return "PROCESSING_INSTRUCTION"; case XMLEvent.CHARACTERS: return "CHARACTERS"; case XMLEvent.COMMENT: return "COMMENT"; case XMLEvent.START_DOCUMENT: return "START_DOCUMENT"; case XMLEvent.END_DOCUMENT: return "END_DOCUMENT"; case XMLEvent.ENTITY_REFERENCE: return "ENTITY_REFERENCE"; case XMLEvent.ATTRIBUTE: return "ATTRIBUTE"; case XMLEvent.DTD: return "DTD"; case XMLEvent.CDATA: return "CDATA"; case XMLEvent.SPACE: return "SPACE"; } return "UNKNOWN_EVENT_TYPE, " + String.valueOf(eventType); }
Example 5
Source File: XMLStreamReaderImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Returns the localName of the attribute at the provided index * * @param index the position of the attribute * @return the localName of the attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public QName getAttributeName(int index) { //State should be either START_ELEMENT or ATTRIBUTE if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return convertXNIQNametoJavaxQName(fScanner.getAttributeIterator().getQualifiedName(index)); } else { throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeName()"); } }
Example 6
Source File: XMLStreamReaderImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** Returns the prefix of this attribute at the * provided index * @param index the position of the attribute * @return the prefix of the attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public String getAttributePrefix(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return fScanner.getAttributeIterator().getPrefix(index); } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributePrefix()") ; } }
Example 7
Source File: XMLStreamReaderImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
final static String getEventTypeString(int eventType) { switch (eventType){ case XMLEvent.START_ELEMENT: return "START_ELEMENT"; case XMLEvent.END_ELEMENT: return "END_ELEMENT"; case XMLEvent.PROCESSING_INSTRUCTION: return "PROCESSING_INSTRUCTION"; case XMLEvent.CHARACTERS: return "CHARACTERS"; case XMLEvent.COMMENT: return "COMMENT"; case XMLEvent.START_DOCUMENT: return "START_DOCUMENT"; case XMLEvent.END_DOCUMENT: return "END_DOCUMENT"; case XMLEvent.ENTITY_REFERENCE: return "ENTITY_REFERENCE"; case XMLEvent.ATTRIBUTE: return "ATTRIBUTE"; case XMLEvent.DTD: return "DTD"; case XMLEvent.CDATA: return "CDATA"; case XMLEvent.SPACE: return "SPACE"; } return "UNKNOWN_EVENT_TYPE, " + String.valueOf(eventType); }
Example 8
Source File: XMLStreamReaderImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** Returns the localName of the attribute at the provided * index * @param index the position of the attribute * @return the localName of the attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public QName getAttributeName(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return convertXNIQNametoJavaxQName(fScanner.getAttributeIterator().getQualifiedName(index)) ; } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeName()") ; } }
Example 9
Source File: XMLStreamReaderImpl.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** Returns the namespace of the attribute at the provided * index * @param index the position of the attribute * @return the namespace URI (can be null) * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public String getAttributeNamespace(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return fScanner.getAttributeIterator().getURI(index); } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeNamespace()") ; } }
Example 10
Source File: XMLStreamReaderImpl.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
final static String getEventTypeString(int eventType) { switch (eventType){ case XMLEvent.START_ELEMENT: return "START_ELEMENT"; case XMLEvent.END_ELEMENT: return "END_ELEMENT"; case XMLEvent.PROCESSING_INSTRUCTION: return "PROCESSING_INSTRUCTION"; case XMLEvent.CHARACTERS: return "CHARACTERS"; case XMLEvent.COMMENT: return "COMMENT"; case XMLEvent.START_DOCUMENT: return "START_DOCUMENT"; case XMLEvent.END_DOCUMENT: return "END_DOCUMENT"; case XMLEvent.ENTITY_REFERENCE: return "ENTITY_REFERENCE"; case XMLEvent.ATTRIBUTE: return "ATTRIBUTE"; case XMLEvent.DTD: return "DTD"; case XMLEvent.CDATA: return "CDATA"; case XMLEvent.SPACE: return "SPACE"; } return "UNKNOWN_EVENT_TYPE, " + String.valueOf(eventType); }
Example 11
Source File: XMLStreamReaderImpl.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** Returns the XML type of the attribute at the provided * index * @param index the position of the attribute * @return the XML type of the attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public String getAttributeType(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return fScanner.getAttributeIterator().getType(index) ; } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeType()") ; } }
Example 12
Source File: XMLStreamReaderImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** Returns the prefix of this attribute at the * provided index * @param index the position of the attribute * @return the prefix of the attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public String getAttributePrefix(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return fScanner.getAttributeIterator().getPrefix(index); } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributePrefix()") ; } }
Example 13
Source File: XMLStreamReaderImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** Returns the prefix of this attribute at the * provided index * @param index the position of the attribute * @return the prefix of the attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public String getAttributePrefix(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return fScanner.getAttributeIterator().getPrefix(index); } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributePrefix()") ; } }
Example 14
Source File: XMLStreamReaderImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * @param index * @return */ public String getAttributeLocalName(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return fScanner.getAttributeIterator().getLocalName(index) ; } else{ throw new java.lang.IllegalStateException() ; } }
Example 15
Source File: XMLStreamReaderImpl.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** Returns the qname of the attribute at the provided index * * @param index the position of the attribute * @return the QName of the attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public javax.xml.namespace.QName getAttributeQName(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { // create new object at runtime.. String localName = fScanner.getAttributeIterator().getLocalName(index) ; String uri = fScanner.getAttributeIterator().getURI(index) ; return new javax.xml.namespace.QName(uri, localName) ; } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeQName()") ; } }
Example 16
Source File: XMLStreamReaderImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
final static String getEventTypeString(int eventType) { switch (eventType) { case XMLEvent.START_ELEMENT: return "START_ELEMENT"; case XMLEvent.END_ELEMENT: return "END_ELEMENT"; case XMLEvent.PROCESSING_INSTRUCTION: return "PROCESSING_INSTRUCTION"; case XMLEvent.CHARACTERS: return "CHARACTERS"; case XMLEvent.COMMENT: return "COMMENT"; case XMLEvent.START_DOCUMENT: return "START_DOCUMENT"; case XMLEvent.END_DOCUMENT: return "END_DOCUMENT"; case XMLEvent.ENTITY_REFERENCE: return "ENTITY_REFERENCE"; case XMLEvent.ATTRIBUTE: return "ATTRIBUTE"; case XMLEvent.DTD: return "DTD"; case XMLEvent.CDATA: return "CDATA"; case XMLEvent.SPACE: return "SPACE"; } return "UNKNOWN_EVENT_TYPE, " + String.valueOf(eventType); }
Example 17
Source File: StAXEventAllocatorBase.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }
Example 18
Source File: StAXEventAllocatorBase.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }
Example 19
Source File: StAXEventAllocatorBase.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }
Example 20
Source File: XMLToImportantChemicals.java From act with GNU General Public License v3.0 | 4 votes |
private void process(XMLStreamReader xml) throws XMLStreamException { String tag; String root = null; Stack<DBObject> json = new Stack<DBObject>(); DBObject js; while (xml.hasNext()) { int eventType = xml.next(); while (xml.isWhiteSpace() || eventType == XMLEvent.SPACE) eventType = xml.next(); switch (eventType) { case XMLEvent.START_ELEMENT: tag = xml.getLocalName(); if (root == null) { root = tag; } else { json.push(new BasicDBObject()); } break; case XMLEvent.END_ELEMENT: tag = xml.getLocalName(); if (tag.equals(root)) { // will terminate in next iteration } else { js = json.pop(); if (json.size() == 0) { if (tag.equals(rowTag)) printEntry(js); else printUnwantedEntry(js); } else { putListStrOrJSON(json.peek(), tag, js); } } break; case XMLEvent.CHARACTERS: String txt = xml.getText(); js = json.peek(); if (js.containsField(strTag)) { txt = js.get(strTag) + txt; js.removeField(strTag); } js.put(strTag, txt); break; case XMLEvent.START_DOCUMENT: break; case XMLEvent.END_DOCUMENT: break; case XMLEvent.COMMENT: case XMLEvent.ENTITY_REFERENCE: case XMLEvent.ATTRIBUTE: case XMLEvent.PROCESSING_INSTRUCTION: case XMLEvent.DTD: case XMLEvent.CDATA: case XMLEvent.SPACE: System.out.format("%s --\n", eventType); break; } } }