List of usage examples for javax.xml.stream XMLStreamReader getPIData
public String getPIData();
From source file:Main.java
public static void printPIData(XMLStreamReader xmlr) { if (xmlr.getEventType() == XMLEvent.PROCESSING_INSTRUCTION) { System.out.print("<?" + xmlr.getPITarget() + " " + xmlr.getPIData() + "?>"); }// ww w. j av a2s . com }
From source file:StaxCursorTest.java
private static void printPIData(XMLStreamReader xmlr) { if (xmlr.getEventType() == XMLEvent.PROCESSING_INSTRUCTION) { System.out.print("<?" + xmlr.getPITarget() + " " + xmlr.getPIData() + "?>"); }//from ww w . jav a 2s . co m }
From source file:Main.java
private static void printPIData(XMLStreamReader xmlr) { if (xmlr.getEventType() == XMLEvent.PROCESSING_INSTRUCTION) { System.out.println(" PI target = " + xmlr.getPITarget()); System.out.println(" PI Data = " + xmlr.getPIData()); }/* ww w.jav a 2 s. c o m*/ }
From source file:XmlReaderToWriter.java
public static void write(XMLStreamReader xmlr, XMLStreamWriter writer) throws XMLStreamException { switch (xmlr.getEventType()) { case XMLEvent.START_ELEMENT: final String localName = xmlr.getLocalName(); final String namespaceURI = xmlr.getNamespaceURI(); if (namespaceURI != null && namespaceURI.length() > 0) { final String prefix = xmlr.getPrefix(); if (prefix != null) writer.writeStartElement(prefix, localName, namespaceURI); else/*from w w w. j av a 2 s . c o m*/ writer.writeStartElement(namespaceURI, localName); } else { writer.writeStartElement(localName); } for (int i = 0, len = xmlr.getNamespaceCount(); i < len; i++) { writer.writeNamespace(xmlr.getNamespacePrefix(i), xmlr.getNamespaceURI(i)); } for (int i = 0, len = xmlr.getAttributeCount(); i < len; i++) { String attUri = xmlr.getAttributeNamespace(i); if (attUri != null) writer.writeAttribute(attUri, xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); else writer.writeAttribute(xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); } break; case XMLEvent.END_ELEMENT: writer.writeEndElement(); break; case XMLEvent.SPACE: case XMLEvent.CHARACTERS: writer.writeCharacters(xmlr.getTextCharacters(), xmlr.getTextStart(), xmlr.getTextLength()); break; case XMLEvent.PROCESSING_INSTRUCTION: writer.writeProcessingInstruction(xmlr.getPITarget(), xmlr.getPIData()); break; case XMLEvent.CDATA: writer.writeCData(xmlr.getText()); break; case XMLEvent.COMMENT: writer.writeComment(xmlr.getText()); break; case XMLEvent.ENTITY_REFERENCE: writer.writeEntityRef(xmlr.getLocalName()); break; case XMLEvent.START_DOCUMENT: String encoding = xmlr.getCharacterEncodingScheme(); String version = xmlr.getVersion(); if (encoding != null && version != null) writer.writeStartDocument(encoding, version); else if (version != null) writer.writeStartDocument(xmlr.getVersion()); break; case XMLEvent.END_DOCUMENT: writer.writeEndDocument(); break; case XMLEvent.DTD: writer.writeDTD(xmlr.getText()); break; } }
From source file:Main.java
/** * Borrowed from org.apache.xml.security.test.stax.utils.XmlReaderToWriter *//*from ww w .ja v a2 s .c om*/ public static void write(XMLStreamReader xmlr, XMLStreamWriter writer) throws XMLStreamException { switch (xmlr.getEventType()) { case XMLEvent.START_ELEMENT: final String localName = xmlr.getLocalName(); final String namespaceURI = xmlr.getNamespaceURI(); if (namespaceURI != null && namespaceURI.length() > 0) { final String prefix = xmlr.getPrefix(); if (prefix != null) { writer.writeStartElement(prefix, localName, namespaceURI); } else { writer.writeStartElement(namespaceURI, localName); } } else { writer.writeStartElement(localName); } for (int i = 0, len = xmlr.getNamespaceCount(); i < len; i++) { String prefix = xmlr.getNamespacePrefix(i); if (prefix == null) { writer.writeDefaultNamespace(xmlr.getNamespaceURI(i)); } else { writer.writeNamespace(prefix, xmlr.getNamespaceURI(i)); } } for (int i = 0, len = xmlr.getAttributeCount(); i < len; i++) { final String attUri = xmlr.getAttributeNamespace(i); if (attUri != null && attUri.length() > 0) { final String prefix = xmlr.getAttributePrefix(i); if (prefix != null) { writer.writeAttribute(prefix, attUri, xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); } else { writer.writeAttribute(attUri, xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); } } else { writer.writeAttribute(xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); } } break; case XMLEvent.END_ELEMENT: writer.writeEndElement(); break; case XMLEvent.SPACE: case XMLEvent.CHARACTERS: char[] text = new char[xmlr.getTextLength()]; xmlr.getTextCharacters(0, text, 0, xmlr.getTextLength()); writer.writeCharacters(text, 0, text.length); break; case XMLEvent.PROCESSING_INSTRUCTION: writer.writeProcessingInstruction(xmlr.getPITarget(), xmlr.getPIData()); break; case XMLEvent.CDATA: writer.writeCData(xmlr.getText()); break; case XMLEvent.COMMENT: writer.writeComment(xmlr.getText()); break; case XMLEvent.ENTITY_REFERENCE: writer.writeEntityRef(xmlr.getLocalName()); break; case XMLEvent.START_DOCUMENT: String encoding = xmlr.getCharacterEncodingScheme(); String version = xmlr.getVersion(); if (encoding != null && version != null) { writer.writeStartDocument(encoding, version); } else if (version != null) { writer.writeStartDocument(xmlr.getVersion()); } break; case XMLEvent.END_DOCUMENT: writer.writeEndDocument(); break; case XMLEvent.DTD: writer.writeDTD(xmlr.getText()); break; } }
From source file:XmlStreamUtils.java
public static String printEvent(XMLStreamReader xmlr) { StringBuffer b = new StringBuffer(); b.append("EVENT:[" + xmlr.getLocation().getLineNumber() + "][" + xmlr.getLocation().getColumnNumber() + "] "); b.append(getName(xmlr.getEventType())); b.append(" ["); switch (xmlr.getEventType()) { case XMLStreamReader.START_ELEMENT: b.append("<"); printName(xmlr, b);//from w w w . j a va 2 s. co m for (int i = 0; i < xmlr.getNamespaceCount(); i++) { b.append(" "); String n = xmlr.getNamespacePrefix(i); if ("xmlns".equals(n)) { b.append("xmlns=\"" + xmlr.getNamespaceURI(i) + "\""); } else { b.append("xmlns:" + n); b.append("=\""); b.append(xmlr.getNamespaceURI(i)); b.append("\""); } } for (int i = 0; i < xmlr.getAttributeCount(); i++) { b.append(" "); printName(xmlr.getAttributePrefix(i), xmlr.getAttributeNamespace(i), xmlr.getAttributeLocalName(i), b); b.append("=\""); b.append(xmlr.getAttributeValue(i)); b.append("\""); } b.append(">"); break; case XMLStreamReader.END_ELEMENT: b.append("</"); printName(xmlr, b); for (int i = 0; i < xmlr.getNamespaceCount(); i++) { b.append(" "); String n = xmlr.getNamespacePrefix(i); if ("xmlns".equals(n)) { b.append("xmlns=\"" + xmlr.getNamespaceURI(i) + "\""); } else { b.append("xmlns:" + n); b.append("=\""); b.append(xmlr.getNamespaceURI(i)); b.append("\""); } } b.append(">"); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: // b.append(xmlr.getText()); int start = xmlr.getTextStart(); int length = xmlr.getTextLength(); b.append(new String(xmlr.getTextCharacters(), start, length)); break; case XMLStreamReader.PROCESSING_INSTRUCTION: String target = xmlr.getPITarget(); if (target == null) target = ""; String data = xmlr.getPIData(); if (data == null) data = ""; b.append("<?"); b.append(target + " " + data); b.append("?>"); break; case XMLStreamReader.CDATA: b.append("<![CDATA["); if (xmlr.hasText()) b.append(xmlr.getText()); b.append("]]>"); break; case XMLStreamReader.COMMENT: b.append("<!--"); if (xmlr.hasText()) b.append(xmlr.getText()); b.append("-->"); break; case XMLStreamReader.ENTITY_REFERENCE: b.append(xmlr.getLocalName() + "="); if (xmlr.hasText()) b.append("[" + xmlr.getText() + "]"); break; case XMLStreamReader.START_DOCUMENT: b.append("<?xml"); b.append(" version='" + xmlr.getVersion() + "'"); b.append(" encoding='" + xmlr.getCharacterEncodingScheme() + "'"); if (xmlr.isStandalone()) b.append(" standalone='yes'"); else b.append(" standalone='no'"); b.append("?>"); break; } b.append("]"); return b.toString(); }
From source file:org.apache.axiom.om.impl.serialize.StreamingOMSerializer.java
/** * Method serializeProcessingInstruction. * * @param reader// w w w . j a v a 2s . c o m * @param writer * @throws XMLStreamException */ protected void serializeProcessingInstruction(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { writer.writeProcessingInstruction(reader.getPITarget(), reader.getPIData()); }
From source file:org.apache.ode.utils.DOMUtils.java
private static void parse(XMLStreamReader reader, Document doc, Node parent) throws XMLStreamException { int event = reader.getEventType(); while (reader.hasNext()) { switch (event) { case XMLStreamConstants.START_ELEMENT: // create element Element e = doc.createElementNS(reader.getNamespaceURI(), reader.getLocalName()); if (reader.getPrefix() != null && reader.getPrefix() != "") { e.setPrefix(reader.getPrefix()); }/*w w w . j a v a 2s . c om*/ parent.appendChild(e); // copy namespaces for (int ns = 0; ns < reader.getNamespaceCount(); ns++) { String uri = reader.getNamespaceURI(ns); String prefix = reader.getNamespacePrefix(ns); declare(e, uri, prefix); } // copy attributes for (int att = 0; att < reader.getAttributeCount(); att++) { String name = reader.getAttributeLocalName(att); String prefix = reader.getAttributePrefix(att); if (prefix != null && prefix.length() > 0) { name = prefix + ":" + name; } Attr attr = doc.createAttributeNS(reader.getAttributeNamespace(att), name); attr.setValue(reader.getAttributeValue(att)); e.setAttributeNode(attr); } // sub-nodes if (reader.hasNext()) { reader.next(); parse(reader, doc, e); } if (parent instanceof Document) { while (reader.hasNext()) reader.next(); return; } break; case XMLStreamConstants.END_ELEMENT: return; case XMLStreamConstants.CHARACTERS: if (parent != null) { parent.appendChild(doc.createTextNode(reader.getText())); } break; case XMLStreamConstants.COMMENT: if (parent != null) { parent.appendChild(doc.createComment(reader.getText())); } break; case XMLStreamConstants.CDATA: parent.appendChild(doc.createCDATASection(reader.getText())); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData())); break; case XMLStreamConstants.ENTITY_REFERENCE: parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData())); break; case XMLStreamConstants.NAMESPACE: case XMLStreamConstants.ATTRIBUTE: break; default: break; } if (reader.hasNext()) { event = reader.next(); } } }
From source file:org.apache.synapse.commons.json.JsonDataSource.java
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException { XMLStreamReader reader = getReader(); xmlWriter.writeStartDocument();//from w w w .j av a 2 s.c o m while (reader.hasNext()) { int x = reader.next(); switch (x) { case XMLStreamConstants.START_ELEMENT: xmlWriter.writeStartElement(reader.getPrefix(), reader.getLocalName(), reader.getNamespaceURI()); int namespaceCount = reader.getNamespaceCount(); for (int i = namespaceCount - 1; i >= 0; i--) { xmlWriter.writeNamespace(reader.getNamespacePrefix(i), reader.getNamespaceURI(i)); } int attributeCount = reader.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { xmlWriter.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader.getAttributeLocalName(i), reader.getAttributeValue(i)); } break; case XMLStreamConstants.START_DOCUMENT: break; case XMLStreamConstants.CHARACTERS: xmlWriter.writeCharacters(reader.getText()); break; case XMLStreamConstants.CDATA: xmlWriter.writeCData(reader.getText()); break; case XMLStreamConstants.END_ELEMENT: xmlWriter.writeEndElement(); break; case XMLStreamConstants.END_DOCUMENT: xmlWriter.writeEndDocument(); break; case XMLStreamConstants.SPACE: break; case XMLStreamConstants.COMMENT: xmlWriter.writeComment(reader.getText()); break; case XMLStreamConstants.DTD: xmlWriter.writeDTD(reader.getText()); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: xmlWriter.writeProcessingInstruction(reader.getPITarget(), reader.getPIData()); break; case XMLStreamConstants.ENTITY_REFERENCE: xmlWriter.writeEntityRef(reader.getLocalName()); break; default: throw new OMException(); } } xmlWriter.writeEndDocument(); xmlWriter.flush(); xmlWriter.close(); }
From source file:org.atomserver.core.validators.SimpleXMLContentValidator.java
private void touchEvent(XMLStreamReader reader) throws XMLStreamException { int eventCode = reader.next(); String val = null; switch (eventCode) { case XMLStreamReader.START_ELEMENT: val = reader.getLocalName(); if (log.isTraceEnabled()) { log.trace("event = START_ELEMENT"); log.trace("Localname = " + val); }//from w w w. j av a 2 s .c o m break; case XMLStreamReader.END_ELEMENT: val = reader.getLocalName(); if (log.isTraceEnabled()) { log.trace("event = END_ELEMENT"); log.trace("Localname = " + val); } break; case XMLStreamReader.PROCESSING_INSTRUCTION: val = reader.getPIData(); if (log.isTraceEnabled()) { log.trace("event = PROCESSING_INSTRUCTION"); log.trace("PIData = " + val); } break; case XMLStreamReader.CHARACTERS: val = reader.getText(); if (log.isTraceEnabled()) { log.trace("event = CHARACTERS"); log.trace("Characters = " + val); } break; case XMLStreamReader.COMMENT: val = reader.getText(); if (log.isTraceEnabled()) { log.trace("event = COMMENT"); log.trace("Comment = " + val); } break; case XMLStreamReader.SPACE: val = reader.getText(); if (log.isTraceEnabled()) { log.trace("event = SPACE"); log.trace("Space = " + val); } break; case XMLStreamReader.START_DOCUMENT: if (log.isTraceEnabled()) { log.trace("event = START_DOCUMENT"); log.trace("Document Started."); } break; case XMLStreamReader.END_DOCUMENT: if (log.isTraceEnabled()) { log.trace("event = END_DOCUMENT"); log.trace("Document Ended"); } break; case XMLStreamReader.ENTITY_REFERENCE: val = reader.getText(); if (log.isTraceEnabled()) { log.trace("event = ENTITY_REFERENCE"); log.trace("Text = " + val); } break; case XMLStreamReader.DTD: val = reader.getText(); if (log.isTraceEnabled()) { log.trace("event = DTD"); log.trace("DTD = " + val); } break; case XMLStreamReader.CDATA: val = reader.getText(); if (log.isTraceEnabled()) { log.trace("event = CDATA"); log.trace("CDATA = " + val); } break; } }