List of usage examples for javax.xml.stream XMLStreamReader getText
public String getText();
From source file:MainClass.java
public static void main(String[] args) throws Exception { File file = new File("test.xml"); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(file)); while (reader.getEventType() == 6) reader.next();//from www . j a v a 2 s . com int eventTypeID = reader.next(); System.out.println("Hello " + reader.getText()); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { File file = new File("text.xml"); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(file)); int eventTypeID = reader.nextTag(); eventTypeID = reader.nextTag();/*from w w w . j a v a2 s . c o m*/ eventTypeID = reader.next(); System.out.println("Hello " + reader.getText()); }
From source file:EntityReferenceTest.java
public static void main(String[] args) throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream("e.xml")); while (reader.hasNext()) { int event = reader.next(); if (event == XMLStreamConstants.CHARACTERS) System.out.println(reader.getText()); else if (event == XMLStreamConstants.ENTITY_REFERENCE) { System.out.println("en: " + reader.getLocalName()); System.out.println("er: " + reader.getText()); }/*from w ww. j a v a 2 s.co m*/ } inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); reader = inputFactory.createXMLStreamReader(new FileInputStream("e.xml")); while (reader.hasNext()) { int event = reader.next(); if (event == XMLStreamConstants.CHARACTERS) System.out.println(reader.getText()); else if (event == XMLStreamConstants.ENTITY_REFERENCE) { System.out.println("en: " + reader.getLocalName()); System.out.println("er: " + reader.getText()); } } }
From source file:Main.java
public static void main(String args[]) throws Exception { XMLInputFactory xmlif = XMLInputFactory.newInstance(); XMLStreamReader xmlsr = xmlif.createXMLStreamReader(new FileReader("points.xml")); int eventType; while (xmlsr.hasNext()) { eventType = xmlsr.next();/*from w w w . j av a 2 s . co m*/ switch (eventType) { case XMLEvent.START_ELEMENT: System.out.println(xmlsr.getName()); break; case XMLEvent.CHARACTERS: System.out.println(xmlsr.getText()); break; default: break; } } }
From source file:Main.java
public static void printText(XMLStreamReader xmlr) { if (xmlr.hasText()) { System.out.print(xmlr.getText()); }//from w ww.ja v a 2 s . c o m }
From source file:StaxCursorTest.java
private static void printText(XMLStreamReader xmlr) { if (xmlr.hasText()) { System.out.print(xmlr.getText()); }/* w w w. java2 s . c om*/ }
From source file:Main.java
private static void printText(XMLStreamReader xmlr) { if (xmlr.hasText()) { System.out.println("HAS TEXT: " + xmlr.getText()); } else {//from www.j a v a 2 s . com System.out.println("HAS NO TEXT"); } }
From source file:StaxCursorTest.java
private static void printComment(XMLStreamReader xmlr) { if (xmlr.getEventType() == xmlr.COMMENT) { System.out.print("<!--" + xmlr.getText() + "-->"); }/*w w w. j a va2 s . c om*/ }
From source file:Main.java
/** * Load text of the current element./*from w w w. ja v a 2s . c om*/ * @param reader XML reader. * @return Text of the element. * @throws XMLStreamException when the text cannot be read or XML is malformed. */ public static String loadElementText(XMLStreamReader reader) throws XMLStreamException { reader.next(); if (reader.isEndElement()) { return ""; } reader.require(XMLStreamConstants.CHARACTERS, null, null); String text = reader.getText(); reader.next(); reader.require(XMLStreamConstants.END_ELEMENT, null, null); return text; }
From source file:Main.java
public static String parseValue(XMLStreamReader xmlRdr) throws XMLStreamException { // consume start tag xmlRdr.next();// w w w . ja va2 s.c o m String val = null; if (xmlRdr.getEventType() == XMLStreamConstants.CHARACTERS) { val = xmlRdr.getText(); xmlRdr.next(); } skipToEndElement(xmlRdr); return val; }