List of usage examples for javax.xml.stream XMLStreamReader isStandalone
public boolean isStandalone();
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("yourXML.xml"); FileInputStream inputStream = new FileInputStream(file); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(inputStream); System.out.println(reader.getVersion()); System.out.println(reader.isStandalone()); System.out.println(reader.standaloneSet()); System.out.println(reader.getEncoding()); System.out.println(reader.getCharacterEncodingScheme()); parseRestOfDocument(reader);/*from www. j av a2 s . co m*/ }
From source file:StAXStreamTreeViewer.java
private void addStartDocumentNodes(XMLStreamReader reader, DefaultMutableTreeNode current) { DefaultMutableTreeNode version = new DefaultMutableTreeNode(reader.getVersion()); current.add(version);//from w w w . j av a 2s. co m DefaultMutableTreeNode standalone = new DefaultMutableTreeNode(reader.isStandalone()); current.add(standalone); DefaultMutableTreeNode standaloneSet = new DefaultMutableTreeNode(reader.standaloneSet()); current.add(standaloneSet); DefaultMutableTreeNode encoding = new DefaultMutableTreeNode(reader.getEncoding()); current.add(encoding); DefaultMutableTreeNode declaredEncoding = new DefaultMutableTreeNode(reader.getCharacterEncodingScheme()); current.add(declaredEncoding); }
From source file:edu.utah.further.core.xml.stax.XmlStreamElementPrinter.java
@Override public void visitStartDocument(final XMLStreamReader xmlReader) { os.println("<?xml version=" + quote(xmlReader.getVersion()) + " encoding=" + quote(xmlReader.getCharacterEncodingScheme()) + " standalone=" + quote(xmlReader.isStandalone() ? "yes" : "no") + "?>"); }
From source file:Main.java
public static String parse(XMLStreamReader reader) { StringBuffer result = new StringBuffer(); if (reader != null) { try {/*w w w . j av a2 s . c o m*/ while (reader.hasNext()) { switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: result.append("<"); printName(reader, result); printNamespaces(reader, result); printAttributes(reader, result); result.append(">"); break; case XMLStreamConstants.END_ELEMENT: result.append("</"); printName(reader, result); result.append(">"); break; case XMLStreamConstants.SPACE: case XMLStreamConstants.CHARACTERS: int start = reader.getTextStart(); int length = reader.getTextLength(); result.append(new String(reader.getTextCharacters(), start, length)); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: result.append("<?"); if (reader.hasText()) result.append(reader.getText()); result.append("?>"); break; case XMLStreamConstants.CDATA: result.append("<![CDATA["); start = reader.getTextStart(); length = reader.getTextLength(); result.append(new String(reader.getTextCharacters(), start, length)); result.append("]]>"); break; case XMLStreamConstants.COMMENT: result.append("<!--"); if (reader.hasText()) result.append(reader.getText()); result.append("-->"); break; case XMLStreamConstants.ENTITY_REFERENCE: result.append(reader.getLocalName()).append("="); if (reader.hasText()) result.append("[").append(reader.getText()).append("]"); break; case XMLStreamConstants.START_DOCUMENT: result.append("<?xml"); result.append(" version='").append(reader.getVersion()).append("'"); result.append(" encoding='").append(reader.getCharacterEncodingScheme()).append("'"); if (reader.isStandalone()) result.append(" standalone='yes'"); else result.append(" standalone='no'"); result.append("?>"); break; } reader.next(); } // end while } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { try { reader.close(); } catch (XMLStreamException e) { } } } return result.toString(); }
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 ww .j a v a2s.c o 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.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void readMessage(final InputStream in) throws XMLStreamException { final XMLStreamReader reader = this.dmClient.createXMLStreamReader(in, ENCODING, new StreamFilter() { @Override/* w ww . j a v a2 s . c o m*/ public boolean accept(final XMLStreamReader reader) { return !reader.isWhiteSpace() && !reader.isStandalone(); } }); jumpToStartTag(reader, "SyncHdr"); //$NON-NLS-1$ readSyncHdr(reader); reader.nextTag(); readSyncBody(reader); reader.nextTag(); reader.close(); }