Java Utililty Methods XML Parse Stream

List of utility methods to do XML Parse Stream

Description

The list of methods to do XML Parse Stream are organized into topic(s).

Method

Stringparse(XMLStreamReader reader)
parse
StringBuffer result = new StringBuffer();
if (reader != null) {
    try {
        while (reader.hasNext()) {
            switch (reader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT:
                result.append("<");
                printName(reader, result);
...
Listparse(XMLStreamReader reader, String... elementNames)
parse
Set<String> set = new HashSet<>();
for (String name : elementNames) {
    set.add(name);
List<String> stateNames = new ArrayList<String>();
while (true) {
    if (reader.getEventType() == END_DOCUMENT) {
        break;
...
DocumentparseDoc(final InputStream is)
parse Doc
try {
    BufferedInputStream in = new BufferedInputStream(is);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource source = new InputSource(in);
    return builder.parse(source);
} finally {
    is.close();
...
DocumentparseInputStream(InputStream in, boolean namespaces, boolean validating)
__UNDOCUMENTED__
DocumentBuilder builder = createDocumentBuilder(namespaces, validating);
return builder.parse(in);
DocumentparseInputStream(InputStream is)
parse Input Stream
try {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(false);
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    return builder.parse(is);
} catch (Exception e) {
    throw new IOException("Error parsing XML Stream", e);
ArrayList>parseMulXML(InputStream is, String[] tagNames)
parse Mul XML
ArrayList<HashMap<String, String>> returnValues = new ArrayList<HashMap<String, String>>();
try {
    DocumentBuilder docBuilder = factory.newDocumentBuilder();
    Document doc = docBuilder.parse(is);
    Element rootElement = doc.getDocumentElement();
    for (int i = 0; i < tagNames.length; i++) {
        NodeList targetNodes = rootElement.getElementsByTagName(tagNames[i]);
        if (targetNodes.getLength() <= 0) {
...
MapparseNamespace(XMLStreamReader reader)
parse Namespace
if (reader.getNamespaceCount() == 0) {
    return Collections.emptyMap();
Map<String, String> prefixToNamespace = new HashMap<String, String>(reader.getNamespaceCount());
int namespaceCount = reader.getNamespaceCount();
for (int i = 0; i < namespaceCount; i++) {
    String namespacePrefix = reader.getNamespacePrefix(i);
    String namespaceURI = reader.getNamespaceURI(namespacePrefix);
...
voidparseNoContent(final XMLStreamReader reader)
parse No Content
while (reader.hasNext()) {
    switch (reader.nextTag()) {
    case XMLStreamConstants.END_ELEMENT: {
        return;
    default: {
        throw unexpectedContent(reader);
throw endOfDocument(reader.getLocation());
intparseNumber(XMLEventReader stream)
parse Number
StringBuilder sb = new StringBuilder(5);
while (stream.peek().isCharacters()) {
    sb.append(stream.nextEvent().asCharacters().getData());
if (!stream.nextEvent().isEndElement()) {
    throw new RuntimeException("Did not end up with end tag while parsing number.");
return Integer.parseInt(sb.toString());
...
Mapparser(InputStream inputStream)
parser
Map<String, String> xmlMap = new HashMap<String, String>();
try {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.parse(inputStream);
    Element root = document.getDocumentElement();
    NodeList nodes = root.getChildNodes();
    int len = nodes.getLength();
...