Example usage for javax.xml.stream XMLStreamReader getName

List of usage examples for javax.xml.stream XMLStreamReader getName

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader getName.

Prototype

public QName getName();

Source Link

Document

Returns a QName for the current START_ELEMENT or END_ELEMENT event

Usage

From source file:net.cloudkit.enterprises.ws.SuperPassQueryTest.java

public static String parsingReceiptData(String responseData) throws XMLStreamException {
    StringBuilder dataBuilder = new StringBuilder("");
    XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(responseData));
    try {//from  w  w  w  .j a  v a 2s.co m
        int event = reader.getEventType();
        while (true) {
            switch (event) {
            case XMLStreamConstants.START_ELEMENT:

                if (reader.getName().toString().equals("TradeName")) {
                    // System.out.println(reader.getElementText());
                    dataBuilder.append(reader.getElementText());
                    dataBuilder.append("\t");
                }
                // System.out.println(reader.getName());
                if (reader.getName().toString().equals("SeqNo")) {
                    // System.out.println(reader.getElementText());
                    dataBuilder.append(reader.getElementText());
                    dataBuilder.append("\t");
                }
                // BillNo
                if (reader.getName().toString().equals("EntryId")) {
                    // System.out.println(reader.getElementText());
                    dataBuilder.append(reader.getElementText());
                    dataBuilder.append("\t");
                }
                if (reader.getName().toString().equals("IEFlag")) {
                    // System.out.println(reader.getElementText());
                    dataBuilder.append(reader.getElementText());
                    dataBuilder.append("\t");
                }
                // ??
                if (reader.getName().toString().equals("IEDate")) {
                    // System.out.println(reader.getElementText());
                    dataBuilder.append(reader.getElementText());
                    dataBuilder.append("\t");
                }
                if (reader.getName().toString().equals("TradeMode")) {
                    // System.out.println(reader.getElementText());
                    dataBuilder.append(reader.getElementText());
                    dataBuilder.append("\t");
                }
                if (reader.getName().toString().equals("Status")) {
                    // System.out.println(reader.getElementText());
                    dataBuilder.append(reader.getElementText());
                    dataBuilder.append("\t");
                }
                if (reader.getName().toString().equals("RetExplain")) {
                    // System.out.println(reader.getElementText());
                    dataBuilder.append(reader.getElementText());
                    dataBuilder.append("\t");
                }
                // NoticeDate
                // CustomsCode
                break;
            case XMLStreamConstants.END_ELEMENT:
                // System.out.println("End Element:" + r.getName());
                break;
            }
            if (!reader.hasNext())
                break;
            event = reader.next();
        }
    } finally {
        reader.close();
    }
    dataBuilder.append("\n");
    return dataBuilder.toString();
}

From source file:net.cloudkit.enterprises.ws.SuperPassQueryTest.java

public static String parsingReceiptStatus(String responseContext) throws XMLStreamException {
    String serviceResponseCode = "-1";
    XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(responseContext));
    try {//from w ww  .  j  a  v  a  2  s  .  c  om
        int event = reader.getEventType();
        while (true) {
            switch (event) {
            case XMLStreamConstants.START_ELEMENT:
                // System.out.println(reader.getName());
                if (reader.getName().toString().equals("ServiceResponseCode")) {
                    // System.out.println(reader.getElementText());
                    serviceResponseCode = reader.getElementText();
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                // System.out.println("End Element:" + r.getName());
                break;
            }
            if (!reader.hasNext())
                break;
            event = reader.next();
        }
    } finally {
        reader.close();
    }
    return serviceResponseCode;
}

From source file:io.cloudslang.content.xml.utils.XmlUtils.java

/**
 * Returns the Namespaces context from an xml.
 *
 * @param xmlString   xml as string/* www .j a  v  a  2s .c  om*/
 * @param xmlFilePath path to xml file
 * @return the Namespaces context from an xml.
 * @throws IOException        file reading exception
 * @throws XMLStreamException parsing exception
 */
public static NamespaceContext getNamespaceContext(String xmlString, String xmlFilePath) throws Exception {
    InputStream inputXML = getStream(xmlString, xmlFilePath);
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(inputXML);
    Map<String, String> namespaces = new HashMap<>();
    while (reader.hasNext()) {
        int evt = reader.next();
        if (evt == XMLStreamConstants.START_ELEMENT) {
            QName qName = reader.getName();
            if (qName != null) {
                if (qName.getPrefix() != null && qName.getPrefix().compareTo("") != 0)
                    namespaces.put(qName.getPrefix(), qName.getNamespaceURI());
            }
        }
    }
    return new SimpleNamespaceContext(namespaces);
}

From source file:com.microsoft.windowsazure.services.table.client.AtomPubParser.java

/**
 * Reserved for internal use. Parses the operation response as a collection of entities. Reads entity data from the
 * specified input stream using the specified class type and optionally projects each entity result with the
 * specified resolver into an {@link ODataPayload} containing a collection of {@link TableResult} objects. .
 * /* w  w  w  .  ja v a 2s .c o m*/
 * @param inStream
 *            The <code>InputStream</code> to read the data to parse from.
 * @param clazzType
 *            The class type <code>T</code> implementing {@link TableEntity} for the entities returned. Set to
 *            <code>null</code> to ignore the returned entities and copy only response properties into the
 *            {@link TableResult} objects.
 * @param resolver
 *            An {@link EntityResolver} instance to project the entities into instances of type <code>R</code>. Set
 *            to <code>null</code> to return the entities as instances of the class type <code>T</code>.
 * @param opContext
 *            An {@link OperationContext} object used to track the execution of the operation.
 * @return
 *         An {@link ODataPayload} containing a collection of {@link TableResult} objects with the parsed operation
 *         response.
 * 
 * @throws XMLStreamException
 *             if an error occurs while accessing the stream.
 * @throws ParseException
 *             if an error occurs while parsing the stream.
 * @throws InstantiationException
 *             if an error occurs while constructing the result.
 * @throws IllegalAccessException
 *             if an error occurs in reflection while parsing the result.
 * @throws StorageException
 *             if a storage service error occurs.
 */
@SuppressWarnings("unchecked")
protected static <T extends TableEntity, R> ODataPayload<?> parseResponse(final InputStream inStream,
        final Class<T> clazzType, final EntityResolver<R> resolver, final OperationContext opContext)
        throws XMLStreamException, ParseException, InstantiationException, IllegalAccessException,
        StorageException {
    ODataPayload<T> corePayload = null;
    ODataPayload<R> resolvedPayload = null;
    ODataPayload<?> commonPayload = null;

    if (resolver != null) {
        resolvedPayload = new ODataPayload<R>();
        commonPayload = resolvedPayload;
    } else {
        corePayload = new ODataPayload<T>();
        commonPayload = corePayload;
    }

    final XMLStreamReader xmlr = Utility.createXMLStreamReaderFromStream(inStream);
    int eventType = xmlr.getEventType();
    xmlr.require(XMLStreamConstants.START_DOCUMENT, null, null);
    eventType = xmlr.next();

    xmlr.require(XMLStreamConstants.START_ELEMENT, null, ODataConstants.FEED);
    // skip feed chars
    eventType = xmlr.next();

    while (xmlr.hasNext()) {
        eventType = xmlr.next();

        if (eventType == XMLStreamConstants.CHARACTERS) {
            xmlr.getText();
            continue;
        }

        final String name = xmlr.getName().toString();

        if (eventType == XMLStreamConstants.START_ELEMENT) {
            if (name.equals(ODataConstants.BRACKETED_ATOM_NS + ODataConstants.ENTRY)) {
                final TableResult res = parseEntity(xmlr, clazzType, resolver, opContext);
                if (corePayload != null) {
                    corePayload.tableResults.add(res);
                }

                if (resolver != null) {
                    resolvedPayload.results.add((R) res.getResult());
                } else {
                    corePayload.results.add((T) res.getResult());
                }
            }
        } else if (eventType == XMLStreamConstants.END_ELEMENT
                && name.equals(ODataConstants.BRACKETED_ATOM_NS + ODataConstants.FEED)) {
            break;
        }
    }

    xmlr.require(XMLStreamConstants.END_ELEMENT, null, ODataConstants.FEED);
    return commonPayload;
}

From source file:com.amalto.core.load.context.BufferStateContextWriter.java

public void writeEndElement(XMLStreamReader reader) throws XMLStreamException {
    ProcessedEndElement endElement = new ProcessedEndElement(reader.getNamespaceURI(), reader.getLocalName(),
            reader.getName().getLocalPart());
    processedElements.add(endElement);//w  w  w.j  a  v a 2 s  . co  m

    // Namespace parsing
    Map<String, String> prefixToNamespace = Utils.parseNamespace(reader);
    Set<Map.Entry<String, String>> entries = prefixToNamespace.entrySet();
    for (Map.Entry<String, String> entry : entries) {
        processedElements.add(new ProcessedEndNamespace(entry.getKey()));
    }
}

From source file:com.predic8.membrane.core.config.AbstractXmlElement.java

protected void parseChildren(XMLStreamReader token, String child) throws Exception {
    int count = 0;
    while (true) { // ignore child
        token.next();/*from   w ww .  j ava  2 s .  c o  m*/
        if (token.isEndElement() && child.equals(token.getName().getLocalPart())) {
            if (count == 0)
                return;
            count--;
        } else if (token.isStartElement() && child.equals(token.getName().getLocalPart())) {
            count++;
        }
    }
}

From source file:org.deegree.protocol.ows.http.OwsHttpResponseImpl.java

private void assertNoExceptionReport(XMLStreamReader xmlStream) throws OWSExceptionReport, XMLStreamException {
    skipStartDocument(xmlStream);// w  w w . jav a  2 s .  c o m
    if (isExceptionReport(xmlStream.getName())) {
        try {
            throw parseExceptionReport(xmlStream);
        } finally {
            close();
        }
    }
}

From source file:edu.utah.further.core.xml.stax.XmlStreamElementPrinter.java

@Override
public void visitEndElement(final XMLStreamReader xmlReader) {
    depth--;//from  w  w w  .  jav  a2s.co  m
    if (depth == 1 && rootElement.equals(xmlReader.getName())) {
        rootElement = null;
    }
    XmlUtil.printEndElement(os, xmlReader);
}

From source file:org.deegree.protocol.ows.http.OwsHttpResponseImpl.java

@Override
public XMLStreamReader getAsXMLStream() throws OWSExceptionReport, XMLStreamException {
    XMLStreamReader xmlStream = xmlFac.createXMLStreamReader(url, is);
    assertNoExceptionReport(xmlStream);// w w w.  java 2 s  .c om
    LOG.debug("Response root element: " + xmlStream.getName());
    String version = xmlStream.getAttributeValue(null, "version");
    LOG.trace("Response version attribute: " + version);
    return xmlStream;
}

From source file:org.maodian.flyingcat.xmpp.state.SelectState.java

@Override
public Result step(XmppContext context, String xml) {
    String fragment = context.wrapStreamTag(xml);
    try (Reader reader = new StringReader(fragment);) {
        try {/*from  w ww.  j a  v  a  2  s.  c o  m*/
            XMLStreamReader xmlsr = XMLInputFactoryHolder.getXMLInputFactory().createXMLStreamReader(reader);
            // skip stream tag
            xmlsr.nextTag();
            xmlsr.nextTag();
            Decoder decoder = context.getGlobalContext().getDecoder(xmlsr.getName());
            ElementVisitee elem = (ElementVisitee) decoder.decode(xmlsr);
            State nextState = elem.acceptElementVisitor(context, elementVisitor);
            Result result = new DefaultResult(nextState);
            return result;
        } catch (XMLStreamException e) {
            throw new XmppException(e, StreamError.BAD_FORMAT);
        }
    } catch (IOException ioe) {
        // close a StringReader/StringWriter should not cause IOException, though
        throw new XmppException(ioe, StreamError.INTERNAL_SERVER_ERROR);
    }
}