private void handleStartElement() throws XMLStreamException, IOException { switch (reader.getLocalName()) { case "property": handleStartProperty(); break; case "name": case "value": case "final": case "source": case "tag": parseToken = true; token.setLength(0); break; case "include": handleInclude(); break; case "fallback": fallbackEntered = true; break; case "configuration": break; default: break; } }
void handleEndElement() throws IOException { String tokenStr = token.toString(); switch (reader.getLocalName()) { case "name": if (token.length() > 0) {
public XmlTokenStream(XMLStreamReader xmlReader, Object sourceRef) { _sourceReference = sourceRef; // Let's ensure we point to START_ELEMENT... if (xmlReader.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new IllegalArgumentException("Invalid XMLStreamReader passed: should be pointing to START_ELEMENT (" +XMLStreamConstants.START_ELEMENT+"), instead got "+xmlReader.getEventType()); } _xmlReader = Stax2ReaderAdapter.wrapIfNecessary(xmlReader); _currentState = XML_START_ELEMENT; _localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); _attributeCount = _xmlReader.getAttributeCount(); }
private final int _initStartElement() throws XMLStreamException { _nextAttributeIndex = 0; _attributeCount = _xmlReader.getAttributeCount(); _localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); return (_currentState = XML_START_ELEMENT); }
public XmlTokenStream(XMLStreamReader xmlReader, Object sourceRef) { _sourceReference = sourceRef; // Let's ensure we point to START_ELEMENT... if (xmlReader.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new IllegalArgumentException("Invalid XMLStreamReader passed: should be pointing to START_ELEMENT (" +XMLStreamConstants.START_ELEMENT+"), instead got "+xmlReader.getEventType()); } _xmlReader = Stax2ReaderAdapter.wrapIfNecessary(xmlReader); _currentState = XML_START_ELEMENT; _localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); _attributeCount = _xmlReader.getAttributeCount(); }
public XmlTokenStream(XMLStreamReader xmlReader, Object sourceRef, int formatFeatures) { _sourceReference = sourceRef; // Let's ensure we point to START_ELEMENT... if (xmlReader.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new IllegalArgumentException("Invalid XMLStreamReader passed: should be pointing to START_ELEMENT (" +XMLStreamConstants.START_ELEMENT+"), instead got "+xmlReader.getEventType()); } _xmlReader = Stax2ReaderAdapter.wrapIfNecessary(xmlReader); _currentState = XML_START_ELEMENT; _localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); _attributeCount = _xmlReader.getAttributeCount(); _formatFeatures = formatFeatures; }
Reader r = new StringReader("<foo><filedata encoding=\"base64\">largeChunkEncodedHere</filedata></foo>"); Writer w = new StringWriter(); XMLInputFactory2 xmlif = (XMLInputFactory2)XMLInputFactory2.newInstance(); XMLStreamReader2 sr = (XMLStreamReader2)xmlif.createXMLStreamReader(r); boolean flag = false; while (sr.hasNext()) { sr.next(); if (sr.getEventType() == XMLStreamConstants.START_ELEMENT) { if ("filedata".equals(sr.getLocalName())) { flag = true; } } else if (sr.getEventType() == XMLStreamConstants.CHARACTERS) { if (flag) { sr.getText(w, false); break; } } } System.out.println(w);
public static String getVersion(String file) throws XMLStreamException, IOException { BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); XMLInputFactory2 ifact = (XMLInputFactory2) XMLInputFactory.newInstance(); ifact.configureForXmlConformance(); XMLStreamReader2 staxXmlReader = (XMLStreamReader2) ifact.createXMLStreamReader(bis); String currentElement; while (staxXmlReader.hasNext()) { int event = staxXmlReader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: currentElement = staxXmlReader.getLocalName(); if (currentElement.equalsIgnoreCase("ONDEX")) { for (int i = 0; i < staxXmlReader.getAttributeCount(); i++) { if (staxXmlReader.getAttributeName(i).getLocalPart().equalsIgnoreCase("version")) { String result = staxXmlReader.getAttributeValue(i); bis.close(); return result; } } } } } return "1.0"; }
writeEntityRef(sr.getLocalName()); return;
_localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); if (_currentWrapper != null) {
_localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); if (_currentWrapper != null) {
protected String convertToString() throws XMLStreamException { // only applicable to cases where START_OBJECT was induced by attributes if (_currentState != XML_ATTRIBUTE_NAME || _nextAttributeIndex != 0) { return null; } String text = _collectUntilTag(); // 23-Dec-2015, tatu: Used to require text not to be null, but as per // [dataformat-xml#167], empty tag does count if (_xmlReader.getEventType() == XMLStreamReader.END_ELEMENT) { if (text == null) { text = ""; } if (_currentWrapper != null) { _currentWrapper = _currentWrapper.getParent(); } // just for diagnostics, reset to element name (from first attribute name) _localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); _attributeCount = 0; _currentState = XML_TEXT; _textValue = text; return text; } // Anything to do in failed case? Roll back whatever we found or.. ? return null; }
/** * Method cursor calls when it needs to track element state information; * if so, it calls this method to take a snapshot of the element. *<p> * Note caller already suppresses calls so that this method is only * called when information needs to be preserved. Further, previous * element is only passed if such linkage is to be preserved (reason * for not always doing it is the increased memory usage). *<p> * Finally, note that this method does NOT implement * {@link ElementInfoFactory}, as its signature does not include the * cursor argument, as that's passed as this pointer already. */ protected SMElementInfo constructElementInfo(SMElementInfo parent, SMElementInfo prevSibling) throws XMLStreamException { if (mElemInfoFactory != null) { return mElemInfoFactory.constructElementInfo(this, parent, prevSibling); } XMLStreamReader2 sr = _streamReader; return new DefaultElementInfo(parent, prevSibling, sr.getPrefix(), sr.getNamespaceURI(), sr.getLocalName(), _nodeCount-1, _elemCount-1, getParentCount()); }
public void writeStartElement(XMLStreamReader2 reader, XMLStreamWriter2 writer) throws XMLStreamException { String uri = reader.getNamespaceURI(); String prefix = reader.getPrefix(); String local = reader.getLocalName(); writer.writeStartElement(prefix, local, uri); // Write out the namespaces for (int i = 0; i < reader.getNamespaceCount(); i++) { String nsURI = reader.getNamespaceURI(i); String nsPrefix = reader.getNamespacePrefix(i); writer.writeNamespace(nsPrefix, nsURI); } }
/** * Method cursor calls when it needs to track element state information; * if so, it calls this method to take a snapshot of the element. *<p> * Note caller already suppresses calls so that this method is only * called when information needs to be preserved. Further, previous * element is only passed if such linkage is to be preserved (reason * for not always doing it is the increased memory usage). *<p> * Finally, note that this method does NOT implement * {@link ElementInfoFactory}, as its signature does not include the * cursor argument, as that's passed as this pointer already. */ protected SMElementInfo constructElementInfo(SMElementInfo parent, SMElementInfo prevSibling) throws XMLStreamException { if (mElemInfoFactory != null) { return mElemInfoFactory.constructElementInfo(this, parent, prevSibling); } XMLStreamReader2 sr = _streamReader; return new DefaultElementInfo(parent, prevSibling, sr.getPrefix(), sr.getNamespaceURI(), sr.getLocalName(), _nodeCount-1, _elemCount-1, getParentCount()); }
_localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); _attributeCount = 0;
/** * For events with fully qualified names (START_ELEMENT, END_ELEMENT, * ATTRIBUTE, NAMESPACE) returns the local component of the full * name; for events with only non-qualified name (PROCESSING_INSTRUCTION, * entity and notation declarations, references) returns the name, and * for other events, returns null. * * @return Local component of the name */ public String getLocalName() throws XMLStreamException { if (!readerAccessible()) { throw _notAccessible("getLocalName"); } switch (getCurrEventCode()) { case XMLStreamConstants.START_ELEMENT: case XMLStreamConstants.END_ELEMENT: case XMLStreamConstants.ENTITY_REFERENCE: return _streamReader.getLocalName(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return _streamReader.getPITarget(); case XMLStreamConstants.DTD: { DTDInfo dtd = _streamReader.getDTDInfo(); return (dtd == null) ? null : dtd.getDTDRootName(); } } return null; }
/** * For events with fully qualified names (START_ELEMENT, END_ELEMENT, * ATTRIBUTE, NAMESPACE) returns the local component of the full * name; for events with only non-qualified name (PROCESSING_INSTRUCTION, * entity and notation declarations, references) returns the name, and * for other events, returns null. * * @return Local component of the name */ public String getLocalName() throws XMLStreamException { if (!readerAccessible()) { throw _notAccessible("getLocalName"); } switch (getCurrEventCode()) { case XMLStreamConstants.START_ELEMENT: case XMLStreamConstants.END_ELEMENT: case XMLStreamConstants.ENTITY_REFERENCE: return _streamReader.getLocalName(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return _streamReader.getPITarget(); case XMLStreamConstants.DTD: { DTDInfo dtd = _streamReader.getDTDInfo(); return (dtd == null) ? null : dtd.getDTDRootName(); } } return null; }
private final int _initStartElement() throws XMLStreamException final String localName = _xmlReader.getLocalName(); _attributeCount = _xmlReader.getAttributeCount(); _nextAttributeIndex = 0;
private final int _initStartElement() throws XMLStreamException final String localName = _xmlReader.getLocalName(); _attributeCount = _xmlReader.getAttributeCount(); _nextAttributeIndex = 0;