List of usage examples for javax.xml.stream XMLStreamReader getAttributeLocalName
public String getAttributeLocalName(int index);
From source file:Main.java
private static void printAttribute(XMLStreamReader xmlr, int index, StringBuffer result) { String prefix = xmlr.getAttributePrefix(index); String namespace = xmlr.getAttributeNamespace(index); String localName = xmlr.getAttributeLocalName(index); String value = xmlr.getAttributeValue(index); result.append(" "); printName(prefix, namespace, localName, result); result.append("='").append(value).append("'"); }
From source file:Main.java
private static void process(XMLStreamReader reader) { int eventType = reader.getEventType(); switch (eventType) { case XMLStreamConstants.START_ELEMENT: System.out.println("Start element: " + reader.getLocalName()); int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { String name = reader.getAttributeLocalName(i); String value = reader.getAttributeValue(i); System.out.println("\tAttribute name/value: " + name + "/" + value); }// w w w. j a va2s . co m break; case XMLStreamConstants.END_ELEMENT: System.out.println("End element: " + reader.getLocalName()); break; case XMLStreamConstants.CHARACTERS: System.out.println("Text: " + reader.getText()); break; default: break; } }
From source file:XMLStreamReaderDemo.java
private static void process(XMLStreamReader reader) { int eventType = reader.getEventType(); switch (eventType) { case XMLStreamConstants.START_ELEMENT: System.out.println("Start element: " + reader.getLocalName()); int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { String name = reader.getAttributeLocalName(i); String value = reader.getAttributeValue(i); System.out.println("\tAttribute name/value: " + name + "/" + value); }//from www .j av a2 s . c o m break; case XMLStreamConstants.END_ELEMENT: System.out.println("End element: " + reader.getLocalName()); break; case XMLStreamConstants.CHARACTERS: System.out.println("Text: " + reader.getText()); break; default: break; } }
From source file:Main.java
public static void dumpXML(XMLStreamReader parser) throws XMLStreamException { int depth = 0; do {/*from w w w .ja v a 2 s . c o m*/ switch (parser.getEventType()) { case XMLStreamConstants.START_ELEMENT: for (int i = 1; i < depth; ++i) { System.out.print(" "); } System.out.print("<"); System.out.print(parser.getLocalName()); for (int i = 0; i < parser.getAttributeCount(); ++i) { System.out.print(" "); System.out.print(parser.getAttributeLocalName(i)); System.out.print("=\""); System.out.print(parser.getAttributeValue(i)); System.out.print("\""); } System.out.println(">"); ++depth; break; case XMLStreamConstants.END_ELEMENT: --depth; for (int i = 1; i < depth; ++i) { System.out.print(" "); } System.out.print("</"); System.out.print(parser.getLocalName()); System.out.println(">"); break; case XMLStreamConstants.CHARACTERS: for (int i = 1; i < depth; ++i) { System.out.print(" "); } System.out.println(parser.getText()); break; } if (depth > 0) parser.next(); } while (depth > 0); }
From source file:edu.utah.further.core.api.xml.XmlUtil.java
/** * @param xmlReader// w w w. ja v a 2s. c o m * @param index */ private static void printAttribute(final PrintStream os, final XMLStreamReader xmlReader, final int index) { final String prefix = xmlReader.getAttributePrefix(index); final String namespace = xmlReader.getAttributeNamespace(index); final String localName = xmlReader.getAttributeLocalName(index); final String value = xmlReader.getAttributeValue(index); os.print(Strings.SPACE_STRING); os.print(getName(prefix, namespace, localName)); os.print("=" + quote(value)); }
From source file:Main.java
private static void parseRestOfDocument(XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext()) { int type = reader.next(); switch (type) { case XMLStreamConstants.START_ELEMENT: System.out.println(reader.getLocalName()); if (reader.getNamespaceURI() != null) { String prefix = reader.getPrefix(); if (prefix == null) { prefix = "[None]"; }//from w ww.j a va 2 s . c o m System.out.println("prefix = '" + prefix + "', URI = '" + reader.getNamespaceURI() + "'"); } if (reader.getAttributeCount() > 0) { for (int i = 0; i < reader.getAttributeCount(); i++) { System.out.println("Attribute (name = '" + reader.getAttributeLocalName(i) + "', value = '" + reader.getAttributeValue(i) + "')"); String attURI = reader.getAttributeNamespace(i); if (attURI != null) { String attPrefix = reader.getAttributePrefix(i); if (attPrefix == null || attPrefix.equals("")) { attPrefix = "[None]"; } System.out.println("prefix=" + attPrefix + ",URI=" + attURI); } } } break; case XMLStreamConstants.END_ELEMENT: System.out.println("XMLStreamConstants.END_ELEMENT"); break; case XMLStreamConstants.CHARACTERS: if (!reader.isWhiteSpace()) { System.out.println("CD:" + reader.getText()); } break; case XMLStreamConstants.DTD: System.out.println("DTD:" + reader.getText()); break; case XMLStreamConstants.SPACE: System.out.println(" "); break; case XMLStreamConstants.COMMENT: System.out.println(reader.getText()); break; default: System.out.println(type); } } }
From source file:MDRevealer.ResistanceTests.java
private static ArrayList<HashMap<String, String>> parse_test(File rt_input) throws XMLStreamException, FileNotFoundException { XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader xsr = xif.createXMLStreamReader(new FileInputStream(rt_input)); ArrayList<HashMap<String, String>> test = new ArrayList<HashMap<String, String>>(); HashMap<String, String> hm = new HashMap<String, String>(); String key = "null"; while (xsr.hasNext() == true) { int constant = xsr.next(); switch (constant) { case XMLStreamConstants.START_ELEMENT: key = xsr.getLocalName();// w ww . ja v a 2 s.co m if (xsr.getAttributeCount() > 0) { for (int i = 0; i < xsr.getAttributeCount(); i++) { hm.put(xsr.getAttributeLocalName(i), xsr.getAttributeValue(i)); } test.add(hm); hm = new HashMap<String, String>(); } break; case XMLStreamConstants.CHARACTERS: if (!xsr.isWhiteSpace()) { hm.put(key, xsr.getText()); test.add(hm); } hm = new HashMap<String, String>(); break; case XMLStreamConstants.END_ELEMENT: if (xsr.getLocalName().equals("condition")) { hm.put("condition_over", "true"); test.add(hm); hm = new HashMap<String, String>(); } break; } } return test; }
From source file:com.stepstone.sonar.plugin.coldfusion.cflint.xml.TagAttribute.java
protected Optional<String> getAttributeValue(String name, XMLStreamReader stream) { for (int i = 0; i < stream.getAttributeCount(); i++) { if (name.equalsIgnoreCase(stream.getAttributeLocalName(i))) { return Optional.of(StringUtils.trimToEmpty(stream.getAttributeValue(i))); }//from www. j a va 2s . c om } return Optional.absent(); }
From source file:lux.index.XmlPathMapper.java
protected void getEventAttQName(MutableString buf, XMLStreamReader reader, int i) { encodeQName(buf, reader.getAttributeLocalName(i), reader.getAttributePrefix(i), reader.getAttributeNamespace(i)); }
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// ww w. ja v a2 s. c om 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; } }