Java XMLStreamReader.getText Examples

Programming Language: Java
Namespace/Package Name: javax.xml.stream
Class/Type: XMLStreamReader
Method/Function: getText
Examples at hotexamples.com: 30
The Java library `javax.xml.stream` provides an interface to read and parse XML documents. One of its methods is `getText()` which is used to retrieve the text content of the current XML element being processed by an `XMLStreamReader`.

Example 1: Retrieving the text content of a specific XML element
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream("document.xml"));
while(reader.hasNext()){
    int eventType = reader.next();
    if(eventType == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals("title")){
        String title = reader.getText();
        System.out.println("Title: " + title);
    }
}

In this example, an `XMLStreamReader` is created to read an XML document. The code loops through the document and when a `` element is encountered, it retrieves the text content of that element using `getText()`.<br><br><b>Example 2:</b> Retrieving the entire text content of an XML document<br><pre style="border:1px solid #888; border-radius: 5px;" class=" language-java">XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream("document.xml")); StringBuilder sb = new StringBuilder(); while(reader.hasNext()){ int eventType = reader.next(); if(eventType == XMLStreamConstants.CHARACTERS){ sb.append(reader.getText()); } } String textContent = sb.toString().trim(); System.out.println("Text Content: " + textContent); </pre> In this example, an `XMLStreamReader` is created to read an XML document. The code loops through the document and appends the text content of each `<text>` element encountered to a `StringBuilder`. Once the entire document has been processed, the text content is retrieved from the `StringBuilder` and trimmed to remove any leading or trailing whitespace. The `javax.xml.stream` library is included in the Java SE platform and does not require any additional libraries or packages to be imported.</div> <strong>Java XMLStreamReader.getText - 30 examples found</strong>. These are the top rated real world Java examples of <strong>javax.xml.stream.XMLStreamReader.getText</strong> extracted from open source projects. You can rate examples to help us improve the quality of examples. </div> </div> <div id="ezoic-pub-ad-placeholder-105"> <div style="text-align: center; margin-top: 10px"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- after-description --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="5330879504" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="visible-xs visible-sm visible-md"> <div class="bs-example thin" style="margin-top: 15px"> <div class="bs-example-title">Frequently Used Methods</div> <div class="fields-controls visible-sm visible-xs visible-md"> <a class="btn btn-default fields-show-btn" data-toggle="collapse" href="#fields-panel-mobile" aria-expanded="false" aria-controls="fields-panel">Show</a> <a class="btn btn-default fields-hide-btn" data-toggle="collapse" href="#fields-panel-mobile" aria-expanded="false" aria-controls="fields-panel">Hide</a> </div> </div> <figure class="highlight panel fields-panel collapse" id="fields-panel-mobile"> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/close/java-xmlstreamreader-close-method-examples.html">close(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getEventType/java-xmlstreamreader-geteventtype-method-examples.html">getEventType(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">getText(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isEndElement/java-xmlstreamreader-isendelement-method-examples.html">isEndElement(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeCount/java-xmlstreamreader-getattributecount-method-examples.html">getAttributeCount(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isStartElement/java-xmlstreamreader-isstartelement-method-examples.html">isStartElement(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getNamespaceURI/java-xmlstreamreader-getnamespaceuri-method-examples.html">getNamespaceURI(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getName/java-xmlstreamreader-getname-method-examples.html">getName(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getLocation/java-xmlstreamreader-getlocation-method-examples.html">getLocation(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getLocalName/java-xmlstreamreader-getlocalname-method-examples.html">getLocalName(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getNamespaceContext/java-xmlstreamreader-getnamespacecontext-method-examples.html">getNamespaceContext(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/next/java-xmlstreamreader-next-method-examples.html">next(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getElementText/java-xmlstreamreader-getelementtext-method-examples.html">getElementText(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeLocalName/java-xmlstreamreader-getattributelocalname-method-examples.html">getAttributeLocalName(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/hasNext/java-xmlstreamreader-hasnext-method-examples.html">hasNext(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/nextTag/java-xmlstreamreader-nexttag-method-examples.html">nextTag(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeValue/java-xmlstreamreader-getattributevalue-method-examples.html">getAttributeValue(30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/require/java-xmlstreamreader-require-method-examples.html">require(27)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeName/java-xmlstreamreader-getattributename-method-examples.html">getAttributeName(19)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeNamespace/java-xmlstreamreader-getattributenamespace-method-examples.html">getAttributeNamespace(16)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/hasText/java-xmlstreamreader-hastext-method-examples.html">hasText(14)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getNamespaceCount/java-xmlstreamreader-getnamespacecount-method-examples.html">getNamespaceCount(12)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isCharacters/java-xmlstreamreader-ischaracters-method-examples.html">isCharacters(12)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getNamespacePrefix/java-xmlstreamreader-getnamespaceprefix-method-examples.html">getNamespacePrefix(11)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributePrefix/java-xmlstreamreader-getattributeprefix-method-examples.html">getAttributePrefix(9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getPrefix/java-xmlstreamreader-getprefix-method-examples.html">getPrefix(9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getTextCharacters/java-xmlstreamreader-gettextcharacters-method-examples.html">getTextCharacters(9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getTextLength/java-xmlstreamreader-gettextlength-method-examples.html">getTextLength(9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getTextStart/java-xmlstreamreader-gettextstart-method-examples.html">getTextStart(9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/hasName/java-xmlstreamreader-hasname-method-examples.html">hasName(8)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getPITarget/java-xmlstreamreader-getpitarget-method-examples.html">getPITarget(7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getProperty/java-xmlstreamreader-getproperty-method-examples.html">getProperty(7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getPIData/java-xmlstreamreader-getpidata-method-examples.html">getPIData(7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeType/java-xmlstreamreader-getattributetype-method-examples.html">getAttributeType(7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isWhiteSpace/java-xmlstreamreader-iswhitespace-method-examples.html">isWhiteSpace(5)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isAttributeSpecified/java-xmlstreamreader-isattributespecified-method-examples.html">isAttributeSpecified(4)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getEncoding/java-xmlstreamreader-getencoding-method-examples.html">getEncoding(4)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getVersion/java-xmlstreamreader-getversion-method-examples.html">getVersion(3)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isStandalone/java-xmlstreamreader-isstandalone-method-examples.html">isStandalone(2)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getCharacterEncodingScheme/java-xmlstreamreader-getcharacterencodingscheme-method-examples.html">getCharacterEncodingScheme(2)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a rel="nofollow" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/standaloneSet/java-xmlstreamreader-standaloneset-method-examples.html">standaloneSet(1)</a> </div> </figure> </div> </div> <div class="page-content-container"> <div class="sidebar hidden-xs hidden-sm hidden-md" style="width:300px"> <div id="ezoic-pub-ad-placeholder-101"> <div style="text-align: center; margin-top: 10px"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- left-sidebar-1 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="7161345231" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="bs-example thin"> <div class="bs-example-title"> Frequently Used Methods </div> </div> <figure class="highlight panel fields-panel " id="fields-panel"> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/close/java-xmlstreamreader-close-method-examples.html">close (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getEventType/java-xmlstreamreader-geteventtype-method-examples.html">getEventType (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">getText (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isEndElement/java-xmlstreamreader-isendelement-method-examples.html">isEndElement (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeCount/java-xmlstreamreader-getattributecount-method-examples.html">getAttributeCount (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isStartElement/java-xmlstreamreader-isstartelement-method-examples.html">isStartElement (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getNamespaceURI/java-xmlstreamreader-getnamespaceuri-method-examples.html">getNamespaceURI (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getName/java-xmlstreamreader-getname-method-examples.html">getName (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getLocation/java-xmlstreamreader-getlocation-method-examples.html">getLocation (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getLocalName/java-xmlstreamreader-getlocalname-method-examples.html">getLocalName (30)</a> </div> </figure> <div id="ezoic-pub-ad-placeholder-102"> <div style="text-align: center; margin-bottom: 10px"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- left-sidebar-2 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="7075206013" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="bs-example thin"> <div class="bs-example-title"> Frequently Used Methods </div> </div> <figure class="highlight panel fields-panel " id="fields-panel"> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getNamespaceContext/java-xmlstreamreader-getnamespacecontext-method-examples.html">getNamespaceContext (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/next/java-xmlstreamreader-next-method-examples.html">next (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getElementText/java-xmlstreamreader-getelementtext-method-examples.html">getElementText (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeLocalName/java-xmlstreamreader-getattributelocalname-method-examples.html">getAttributeLocalName (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/hasNext/java-xmlstreamreader-hasnext-method-examples.html">hasNext (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/nextTag/java-xmlstreamreader-nexttag-method-examples.html">nextTag (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeValue/java-xmlstreamreader-getattributevalue-method-examples.html">getAttributeValue (30)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/require/java-xmlstreamreader-require-method-examples.html">require (27)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeName/java-xmlstreamreader-getattributename-method-examples.html">getAttributeName (19)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeNamespace/java-xmlstreamreader-getattributenamespace-method-examples.html">getAttributeNamespace (16)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/hasText/java-xmlstreamreader-hastext-method-examples.html">hasText (14)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getNamespaceCount/java-xmlstreamreader-getnamespacecount-method-examples.html">getNamespaceCount (12)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isCharacters/java-xmlstreamreader-ischaracters-method-examples.html">isCharacters (12)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getNamespacePrefix/java-xmlstreamreader-getnamespaceprefix-method-examples.html">getNamespacePrefix (11)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributePrefix/java-xmlstreamreader-getattributeprefix-method-examples.html">getAttributePrefix (9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getPrefix/java-xmlstreamreader-getprefix-method-examples.html">getPrefix (9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getTextCharacters/java-xmlstreamreader-gettextcharacters-method-examples.html">getTextCharacters (9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getTextLength/java-xmlstreamreader-gettextlength-method-examples.html">getTextLength (9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getTextStart/java-xmlstreamreader-gettextstart-method-examples.html">getTextStart (9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/hasName/java-xmlstreamreader-hasname-method-examples.html">hasName (8)</a> </div> </figure> <div class="bs-example thin"> <div class="bs-example-title"> Frequently Used Methods </div> </div> <figure class="highlight panel fields-panel " id="fields-panel"> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/hasText/java-xmlstreamreader-hastext-method-examples.html">hasText (14)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getNamespaceCount/java-xmlstreamreader-getnamespacecount-method-examples.html">getNamespaceCount (12)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isCharacters/java-xmlstreamreader-ischaracters-method-examples.html">isCharacters (12)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getNamespacePrefix/java-xmlstreamreader-getnamespaceprefix-method-examples.html">getNamespacePrefix (11)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributePrefix/java-xmlstreamreader-getattributeprefix-method-examples.html">getAttributePrefix (9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getPrefix/java-xmlstreamreader-getprefix-method-examples.html">getPrefix (9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getTextCharacters/java-xmlstreamreader-gettextcharacters-method-examples.html">getTextCharacters (9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getTextLength/java-xmlstreamreader-gettextlength-method-examples.html">getTextLength (9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getTextStart/java-xmlstreamreader-gettextstart-method-examples.html">getTextStart (9)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/hasName/java-xmlstreamreader-hasname-method-examples.html">hasName (8)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getPITarget/java-xmlstreamreader-getpitarget-method-examples.html">getPITarget (7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getProperty/java-xmlstreamreader-getproperty-method-examples.html">getProperty (7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getPIData/java-xmlstreamreader-getpidata-method-examples.html">getPIData (7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeType/java-xmlstreamreader-getattributetype-method-examples.html">getAttributeType (7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isWhiteSpace/java-xmlstreamreader-iswhitespace-method-examples.html">isWhiteSpace (5)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isAttributeSpecified/java-xmlstreamreader-isattributespecified-method-examples.html">isAttributeSpecified (4)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getEncoding/java-xmlstreamreader-getencoding-method-examples.html">getEncoding (4)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getVersion/java-xmlstreamreader-getversion-method-examples.html">getVersion (3)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isStandalone/java-xmlstreamreader-isstandalone-method-examples.html">isStandalone (2)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getCharacterEncodingScheme/java-xmlstreamreader-getcharacterencodingscheme-method-examples.html">getCharacterEncodingScheme (2)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a rel="nofollow" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/standaloneSet/java-xmlstreamreader-standaloneset-method-examples.html">standaloneSet (1)</a> </div> </figure> <div class="hidden-xs hidden-sm"> <div class="bs-example thin"> <div class="bs-example-title">Related in langs</div> </div> <figure class="highlight panel"> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://hotexamples.com/examples/-/-/it_exchange_get_transaction_customer_email/php-it_exchange_get_transaction_customer_email-function-examples.html">it_exchange_get_transaction_customer_email (PHP)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://hotexamples.com/examples/-/-/addJavascriptVar/php-addjavascriptvar-function-examples.html">addJavascriptVar (PHP)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://csharp.hotexamples.com/examples/WpfHint2/HintSource/-/php-hintsource-class-examples.html">HintSource (C#)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://csharp.hotexamples.com/examples/-/FitOrder/-/php-fitorder-class-examples.html">FitOrder (C#)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://cpp.hotexamples.com/examples/-/-/LM_CRIT/cpp-lm_crit-function-examples.html">LM_CRIT (C++)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://cpp.hotexamples.com/examples/-/-/ensureGlContext/cpp-ensureglcontext-function-examples.html">ensureGlContext (C++)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://golang.hotexamples.com/examples/github.com.spf13.viper/-/UnmarshalKey/golang-unmarshalkey-function-examples.html">UnmarshalKey (Go)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://golang.hotexamples.com/examples/google.golang.org.appengine.internal/-/ContextForTesting/golang-contextfortesting-function-examples.html">ContextForTesting (Go)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://python.hotexamples.com/examples/roundup.cgi/TranslationService/-/python-translationservice-class-examples.html">TranslationService (Python)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://python.hotexamples.com/examples/data_structures.graphs.simple_graph/Graph/-/python-graph-class-examples.html">Graph (Python)</a> </div> </figure> </div> <div class="bs-example thin"> <div class="bs-example-title"> Frequently Used Methods </div> </div> <figure class="highlight panel fields-panel fields-panel-last" id="fields-panel"> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getPITarget/java-xmlstreamreader-getpitarget-method-examples.html">getPITarget (7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getProperty/java-xmlstreamreader-getproperty-method-examples.html">getProperty (7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getPIData/java-xmlstreamreader-getpidata-method-examples.html">getPIData (7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getAttributeType/java-xmlstreamreader-getattributetype-method-examples.html">getAttributeType (7)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isWhiteSpace/java-xmlstreamreader-iswhitespace-method-examples.html">isWhiteSpace (5)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isAttributeSpecified/java-xmlstreamreader-isattributespecified-method-examples.html">isAttributeSpecified (4)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getEncoding/java-xmlstreamreader-getencoding-method-examples.html">getEncoding (4)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getVersion/java-xmlstreamreader-getversion-method-examples.html">getVersion (3)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/isStandalone/java-xmlstreamreader-isstandalone-method-examples.html">isStandalone (2)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getCharacterEncodingScheme/java-xmlstreamreader-getcharacterencodingscheme-method-examples.html">getCharacterEncodingScheme (2)</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a rel="nofollow" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/standaloneSet/java-xmlstreamreader-standaloneset-method-examples.html">standaloneSet (1)</a> </div> </figure> <div class="hidden-xs hidden-sm"> <div class="bs-example thin"> <div class="bs-example-title">Related</div> </div> <figure class="highlight panel"> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/org.apache.tools.ant.util/Manifest/-/java-manifest-class-examples.html">Manifest</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/org.androidtransfuse.analysis.adapter/JExpr/-/java-jexpr-class-examples.html">JExpr</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/-/TiffFileInfo/-/java-tifffileinfo-class-examples.html">TiffFileInfo</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/com.google.code.p.keytooliui.shared.lang/OPAbstract/-/java-opabstract-class-examples.html">OPAbstract</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/net.minecraft.client.gui/GL11/-/java-gl11-class-examples.html">GL11</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/org.compiere.util/AEnv/-/java-aenv-class-examples.html">AEnv</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/com.shinymetal.gradereport.objects/TS/-/java-ts-class-examples.html">TS</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/com.about.java.dto/TreeService/-/java-treeservice-class-examples.html">TreeService</a> </div> <div style="overflow: hidden;text-overflow: ellipsis;"> <a href="https://java.hotexamples.com/examples/com.amazonaws.services.ec2.model/EC2AbstractSlave/-/java-ec2abstractslave-class-examples.html">EC2AbstractSlave</a> </div> </figure> </div> </div> <div class="main-content"> <div class="addthis_inline_share_toolbox_o6yp"></div> <div class="example-item" id="0xceee7b941a316a73db38489deb1c1a87c7c954d76b0d1459d66b16a512c333e2-469,,505,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #1</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_1" data-hash="0xceee7b941a316a73db38489deb1c1a87c7c954d76b0d1459d66b16a512c333e2" data-area="469,,505,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '1')" class="rating-up btn btn-success" data-id="rating_1"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'1')" class="rating-down btn btn-danger" data-id="rating_1"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xceee7b941a316a73db38489deb1c1a87c7c954d76b0d1459d66b16a512c333e2-469,,505,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xceee7b941a316a73db38489deb1c1a87c7c954d76b0d1459d66b16a512c333e2&fullName=external%2Fmodules%2Ffelix.woodstox-core-asl%2F4.0.7%2Fsrc%2Ftest%2FBaseStax2Test.java&project=mallampatisuresh%2FGlassfish')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fmallampatisuresh%2FGlassfish%2Fblob%2Fmaster%2Fexternal%2Fmodules%2Ffelix.woodstox-core-asl%2F4.0.7%2Fsrc%2Ftest%2FBaseStax2Test.java">BaseStax2Test.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fmallampatisuresh%2FGlassfish">mallampatisuresh/Glassfish</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="1"> <pre class="line-numbers language-java" data-end="505" data-start="470" data-highlight="481,497"> /** * Method that not only gets currently available text from the reader, but also checks that its * consistenly accessible using different (basic) StAX methods. */ protected static String getAndVerifyText(XMLStreamReader sr) throws XMLStreamException { /* 05-Apr-2006, TSa: Although getText() is available for DTD * and ENTITY_REFERENCE, getTextXxx() are not. Thus, can not * do more checks for those types. */ int type = sr.getEventType(); if (type == ENTITY_REFERENCE || type == DTD) { return sr.getText(); } int expLen = sr.getTextLength(); /* Hmmh. It's only ok to return empty text for DTD event... well, * maybe also for CDATA, since empty CDATA blocks are legal? */ /* !!! 01-Sep-2004, TSa: * note: theoretically, in coalescing mode, it could be possible * to have empty CDATA section(s) get converted to CHARACTERS, * which would be empty... may need to enhance this to check that * mode is not coalescing? Or something */ if (type == CHARACTERS) { assertTrue("Stream reader should never return empty Strings.", (expLen > 0)); } String text = sr.getText(); assertNotNull("getText() should never return null.", text); assertEquals( "Expected text length of " + expLen + ", got " + text.length(), expLen, text.length()); char[] textChars = sr.getTextCharacters(); int start = sr.getTextStart(); String text2 = new String(textChars, start, expLen); assertEquals(text, text2); return text; }</pre> </div> </figure> </div> <div id="ezoic-pub-ad-placeholder-107"> <div style="text-align: center;margin-bottom: 10px"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- after-example-1 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="4981531786" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="example-item" id="0xcd39830ab4ba74f71b2c3f1f7fe4674d67401c1379c2a79bbd00eacd532d505f-266,,295,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #2</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_2" data-hash="0xcd39830ab4ba74f71b2c3f1f7fe4674d67401c1379c2a79bbd00eacd532d505f" data-area="266,,295,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '2')" class="rating-up btn btn-success" data-id="rating_2"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'2')" class="rating-down btn btn-danger" data-id="rating_2"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xcd39830ab4ba74f71b2c3f1f7fe4674d67401c1379c2a79bbd00eacd532d505f-266,,295,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xcd39830ab4ba74f71b2c3f1f7fe4674d67401c1379c2a79bbd00eacd532d505f&fullName=modules%2Factiviti-bpmn-converter%2Fsrc%2Fmain%2Fjava%2Forg%2Factiviti%2Fbpmn%2FBaseBpmnXMLConverter.java&project=rjnole%2FActiviti')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Frjnole%2FActiviti%2Fblob%2Fmaster%2Fmodules%2Factiviti-bpmn-converter%2Fsrc%2Fmain%2Fjava%2Forg%2Factiviti%2Fbpmn%2FBaseBpmnXMLConverter.java">BaseBpmnXMLConverter.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Frjnole%2FActiviti">rjnole/Activiti</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="2"> <pre class="line-numbers language-java" data-end="295" data-start="267" data-highlight="284,285"> @SuppressWarnings("unchecked") protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception { ExtensionElement extensionElement = new ExtensionElement(); extensionElement.setName(xtr.getLocalName()); if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) { extensionElement.setNamespace(xtr.getNamespaceURI()); } if (StringUtils.isNotEmpty(xtr.getPrefix())) { extensionElement.setNamespacePrefix(xtr.getPrefix()); } BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes); boolean readyWithExtensionElement = false; while (readyWithExtensionElement == false && xtr.hasNext()) { xtr.next(); if (xtr.isCharacters()) { if (StringUtils.isNotEmpty(xtr.getText().trim())) { extensionElement.setElementText(xtr.getText().trim()); } } else if (xtr.isStartElement()) { ExtensionElement childExtensionElement = parseExtensionElement(xtr); extensionElement.addChildElement(childExtensionElement); } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) { readyWithExtensionElement = true; } } return extensionElement; }</pre> </div> </figure> </div> <div id="ezoic-pub-ad-placeholder-108"> <div style="text-align: center;"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- after-example-2 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="7155150962" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="example-item" id="0x0db59b444a2442fde2f8abfb31c57d267bc709f49c2ab28249db221a898d7443-272,,305,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #3</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_3" data-hash="0x0db59b444a2442fde2f8abfb31c57d267bc709f49c2ab28249db221a898d7443" data-area="272,,305,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '3')" class="rating-up btn btn-success" data-id="rating_3"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'3')" class="rating-down btn btn-danger" data-id="rating_3"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x0db59b444a2442fde2f8abfb31c57d267bc709f49c2ab28249db221a898d7443-272,,305,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x0db59b444a2442fde2f8abfb31c57d267bc709f49c2ab28249db221a898d7443&fullName=weasis-dicom%2Fweasis-dicom-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fweasis%2Fdicom%2Fcodec%2FModalityView.java&project=nroduit%2FWeasis')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fnroduit%2FWeasis%2Fblob%2Fmaster%2Fweasis-dicom%2Fweasis-dicom-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fweasis%2Fdicom%2Fcodec%2FModalityView.java">ModalityView.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fnroduit%2FWeasis">nroduit/Weasis</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="3"> <pre class="line-numbers language-java" data-end="305" data-start="273" data-highlight="285"> private static void readCorner(ModalityInfoData data, CornerDisplay corner, XMLStreamReader xmler) throws XMLStreamException { TagView[] disElements = data.getCornerInfo(corner).getInfos(); boolean state = true; int index = -1; String format = null; while (xmler.hasNext() && state) { switch (xmler.next()) { case XMLStreamConstants.CHARACTERS: if (index > 0 && index <= 7) { disElements[index - 1] = getTag(xmler.getText(), format); index = -1; // Reset current index and format format = null; } break; case XMLStreamConstants.START_ELEMENT: if ("p".equals(xmler.getName().getLocalPart()) && xmler.getAttributeCount() >= 1) { // $NON-NLS-1$ index = TagUtil.getIntegerTagAttribute(xmler, "index", -1); // $NON-NLS-1$ format = xmler.getAttributeValue(null, "format"); // $NON-NLS-1$ } break; case XMLStreamConstants.END_ELEMENT: if ("corner".equals(xmler.getName().getLocalPart())) { // $NON-NLS-1$ state = false; } break; default: break; } } }</pre> </div> </figure> </div> <div id="ezoic-pub-ad-placeholder-109"> <div style="text-align: center;"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- after-example-3 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="8699811701" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="example-item" id="0x0aff6a6203bc4c6af53d438331adc427b9f68cd9618f95e86faebebfefed5b10-93,,121,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #4</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_4" data-hash="0x0aff6a6203bc4c6af53d438331adc427b9f68cd9618f95e86faebebfefed5b10" data-area="93,,121,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '4')" class="rating-up btn btn-success" data-id="rating_4"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'4')" class="rating-down btn btn-danger" data-id="rating_4"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x0aff6a6203bc4c6af53d438331adc427b9f68cd9618f95e86faebebfefed5b10-93,,121,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x0aff6a6203bc4c6af53d438331adc427b9f68cd9618f95e86faebebfefed5b10&fullName=src%2Fcom%2Ferwandano%2Ffsdiff%2FFSHXLoadTask.java&project=Braincoke%2FFSDiff')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FBraincoke%2FFSDiff%2Fblob%2Fmaster%2Fsrc%2Fcom%2Ferwandano%2Ffsdiff%2FFSHXLoadTask.java">FSHXLoadTask.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FBraincoke%2FFSDiff">Braincoke/FSDiff</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="4"> <pre class="line-numbers language-java" data-end="121" data-start="94" data-highlight="108"> /** Extract the metadata of a file system hash */ public FileSystemHashMetadata loadFileSystemHashMetadata() throws XMLStreamException { String endTag = "metadata"; HashMap<String, String> fshMetadata = new HashMap<>(); int type; String currentElement; boolean done = false; while (!done && reader.hasNext()) { type = reader.next(); if (type == XMLStreamReader.START_ELEMENT) { currentElement = reader.getLocalName(); type = reader.next(); if (type == XMLStreamReader.CHARACTERS) { fshMetadata.put(currentElement, reader.getText()); // Look for the end of the current element and throw an exception if it cannot be found do { type = reader.next(); } while (type != XMLStreamReader.END_ELEMENT); verifyClosing(currentElement); } else if (type == XMLStreamReader.END_ELEMENT) { verifyClosing(currentElement); } } else if (type == XMLStreamReader.END_ELEMENT) { done = reader.getLocalName().compareTo(endTag) == 0; } } return new FileSystemHashMetadata(fshMetadata); }</pre> </div> </figure> </div> <div class="example-item" id="0x8ecd622af4387f2fd85b1f64ef33cc5ab80559f05e5ebd6783c55200079d1ef3-16,,44,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #5</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_5" data-hash="0x8ecd622af4387f2fd85b1f64ef33cc5ab80559f05e5ebd6783c55200079d1ef3" data-area="16,,44,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '5')" class="rating-up btn btn-success" data-id="rating_5"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'5')" class="rating-down btn btn-danger" data-id="rating_5"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x8ecd622af4387f2fd85b1f64ef33cc5ab80559f05e5ebd6783c55200079d1ef3-16,,44,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x8ecd622af4387f2fd85b1f64ef33cc5ab80559f05e5ebd6783c55200079d1ef3&fullName=src%2Fcom%2Fxml%2FUnknownStructureXmlParser.java&project=olegbezk%2FParseUnknownXML')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Folegbezk%2FParseUnknownXML%2Fblob%2Fmaster%2Fsrc%2Fcom%2Fxml%2FUnknownStructureXmlParser.java">UnknownStructureXmlParser.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Folegbezk%2FParseUnknownXML">olegbezk/ParseUnknownXML</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="5"> <pre class="line-numbers language-java" data-end="44" data-start="17" data-highlight="37"> public Stack<Map<String, String>> parseXml(File file) throws Exception { String name = "", value; Stack<Map<String, String>> rows = new Stack<>(); XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream(file)); while (xr.hasNext()) { int e = xr.next(); switch (e) { case XMLStreamReader.START_ELEMENT: { name = xr.getLocalName(); break; } case XMLStreamReader.CHARACTERS: { Map<String, String> map = newHashMap(); value = xr.getText(); map.put(name, value); rows.push(map); break; } } } return rows; }</pre> </div> </figure> </div> <div class="example-item" id="0x02dabc02ddece3125e90e1ac8a9534ea295c109d8067fef7785f39a68cadf4ed-167,,201,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #6</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_6" data-hash="0x02dabc02ddece3125e90e1ac8a9534ea295c109d8067fef7785f39a68cadf4ed" data-area="167,,201,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '6')" class="rating-up btn btn-success" data-id="rating_6"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'6')" class="rating-down btn btn-danger" data-id="rating_6"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x02dabc02ddece3125e90e1ac8a9534ea295c109d8067fef7785f39a68cadf4ed-167,,201,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x02dabc02ddece3125e90e1ac8a9534ea295c109d8067fef7785f39a68cadf4ed&fullName=src%2Fmain%2Fjava%2Forg%2Faanguita%2Fjacuzzi%2Fio%2FXMLDom.java&project=albertoanguita%2Fjacuzzi')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Falbertoanguita%2Fjacuzzi%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Forg%2Faanguita%2Fjacuzzi%2Fio%2FXMLDom.java">XMLDom.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Falbertoanguita%2Fjacuzzi">albertoanguita/jacuzzi</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="6"> <pre class="line-numbers language-java" data-end="201" data-start="168" data-highlight="193"> private static Element parseElement(XMLStreamReader xsr) throws XMLStreamException { // xsr points to a START_ELEMENT event. Create the element and read all its attributes // Then read all its children events Element element = new Element(xsr.getLocalName()); // text that will be added to the element. Text can come in different events, so we add it here // and add it to the element at the end StringBuilder elementText = new StringBuilder(); int attributeCount = xsr.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { element.putAttribute(xsr.getAttributeLocalName(i), xsr.getAttributeValue(i)); } while (xsr.hasNext()) { xsr.next(); if (xsr.getEventType() == XMLStreamConstants.END_ELEMENT) { // element is closed. Move the cursor and return it // check if there is some text to add before (empty text is not added, but added text is not // trimmed) // we set empty text also if the element has no children if (!elementText.toString().trim().isEmpty() || !element.hasChildren()) { element.setText(elementText.toString()); } // xsr.next(); return element; } else if (xsr.getEventType() == XMLStreamConstants.CHARACTERS) { // an attribute of the current element elementText.append(xsr.getText()); } else if (xsr.getEventType() == XMLStreamConstants.START_ELEMENT) { // new element begins -> read it recursively and add it to the current element element.addChild(parseElement(xsr)); } } // we reached the end of the document without the tag end -> error parsing throw new XMLStreamException( "End of the document unexpectedly reached. Element " + element.getName() + " not closed"); }</pre> </div> </figure> </div> <div class="example-item" id="0x9aaef634d553c5bb02f6a0750380afe23d9a4260d9f41230b7af4d4d4dfe8228-366,,372,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #7</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_7" data-hash="0x9aaef634d553c5bb02f6a0750380afe23d9a4260d9f41230b7af4d4d4dfe8228" data-area="366,,372,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '7')" class="rating-up btn btn-success" data-id="rating_7"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'7')" class="rating-down btn btn-danger" data-id="rating_7"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x9aaef634d553c5bb02f6a0750380afe23d9a4260d9f41230b7af4d4d4dfe8228-366,,372,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x9aaef634d553c5bb02f6a0750380afe23d9a4260d9f41230b7af4d4d4dfe8228&fullName=src%2Forg%2Fapache%2Faxiom%2Futil%2FXMLFragmentStreamReader.java&project=a13m%2Fwsdl2c')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fa13m%2Fwsdl2c%2Fblob%2Fmaster%2Fsrc%2Forg%2Fapache%2Faxiom%2Futil%2FXMLFragmentStreamReader.java">XMLFragmentStreamReader.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fa13m%2Fwsdl2c">a13m/wsdl2c</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="7"> <pre class="line-numbers language-java" data-end="372" data-start="367" data-highlight="371"> public String getText() { if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) { throw new IllegalStateException(); } else { return parent.getText(); } }</pre> </div> </figure> </div> <div class="example-item" id="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-407,,444,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #8</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_8" data-hash="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4" data-area="407,,444,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '8')" class="rating-up btn btn-success" data-id="rating_8"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'8')" class="rating-down btn btn-danger" data-id="rating_8"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-407,,444,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4&fullName=src%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java&project=jbartece%2Fundertow4jenkins')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins%2Fblob%2Fmaster%2Fsrc%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java">WebXmlParser.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins">jbartece/undertow4jenkins</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="8"> <pre class="line-numbers language-java" data-end="444" data-start="408" data-highlight="421"> // <security-role> // <role-name>admin</role-name> // </security-role> private String loadSecurityRole(XMLStreamReader xmlReader) throws WebXmlFormatException, XMLStreamException { String tagContent = null; String tagName; String roleName = null; while (xmlReader.hasNext()) { switch (xmlReader.next()) { case XMLStreamConstants.CHARACTERS: tagContent = xmlReader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: tagName = xmlReader.getLocalName(); if (tagName.equals("role-name")) { roleName = tagContent; continue; } if (tagName.equals("security-role")) { if (roleName == null) throwExceptionNotSpecifiedParameter("Security-role", "role-name"); else return roleName; } break; default: break; } } throwMalformedWebXml("security-role"); return null; // Never happens. Method above always throws exception }</pre> </div> </figure> </div> <div class="example-item" id="0xc09aeb3ec38db537905b17d6ca0d79628b48a24f58d471469b5ca4bac39d9ca5-247,,286,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #9</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_9" data-hash="0xc09aeb3ec38db537905b17d6ca0d79628b48a24f58d471469b5ca4bac39d9ca5" data-area="247,,286,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '9')" class="rating-up btn btn-success" data-id="rating_9"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'9')" class="rating-down btn btn-danger" data-id="rating_9"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xc09aeb3ec38db537905b17d6ca0d79628b48a24f58d471469b5ca4bac39d9ca5-247,,286,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xc09aeb3ec38db537905b17d6ca0d79628b48a24f58d471469b5ca4bac39d9ca5&fullName=src%2Forg%2Fapache%2Faxiom%2Fom%2Fimpl%2FStAXBuilder.java&project=a13m%2Fwsdl2c')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fa13m%2Fwsdl2c%2Fblob%2Fmaster%2Fsrc%2Forg%2Fapache%2Faxiom%2Fom%2Fimpl%2FStAXBuilder.java">StAXBuilder.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fa13m%2Fwsdl2c">a13m/wsdl2c</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="9"> <pre class="line-numbers language-java" data-end="286" data-start="248" data-highlight="280"> /** * This method will check whether the text can be optimizable using IS_BINARY flag. If that is set * then we try to get the data handler. * * @param omContainer * @param textType * @return omNode */ private OMNode createOMText(OMContainer omContainer, int textType) { if (dataHandlerReader != null && dataHandlerReader.isBinary()) { Object dataHandlerObject; if (dataHandlerReader.isDeferred()) { dataHandlerObject = dataHandlerReader.getDataHandlerProvider(); } else { try { dataHandlerObject = dataHandlerReader.getDataHandler(); } catch (XMLStreamException ex) { throw new OMException(ex); } } OMText text = omfactory.createOMText(dataHandlerObject, dataHandlerReader.isOptimized()); String contentID = dataHandlerReader.getContentID(); if (contentID != null) { text.setContentID(contentID); } omContainer.addChild(text); return text; } else { // Some parsers (like Woodstox) parse text nodes lazily and may throw a // RuntimeException in getText() String text; try { text = parser.getText(); } catch (RuntimeException ex) { parserException = ex; throw ex; } return omfactory.createOMText(omContainer, text, textType); } }</pre> </div> </figure> </div> <div class="example-item" id="0x725cdf050ef8d66e95d110f2a135355f51049c11710586aed6d653918d8a2d6b-90,,146,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #10</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_10" data-hash="0x725cdf050ef8d66e95d110f2a135355f51049c11710586aed6d653918d8a2d6b" data-area="90,,146,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '10')" class="rating-up btn btn-success" data-id="rating_10"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'10')" class="rating-down btn btn-danger" data-id="rating_10"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x725cdf050ef8d66e95d110f2a135355f51049c11710586aed6d653918d8a2d6b-90,,146,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x725cdf050ef8d66e95d110f2a135355f51049c11710586aed6d653918d8a2d6b&fullName=camel-core%2Fsrc%2Ftest%2Fjava%2Forg%2Fapache%2Fcamel%2Fconverter%2FStaxConverterTest.java&project=robobario%2Fcamel')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Frobobario%2Fcamel%2Fblob%2Fmaster%2Fcamel-core%2Fsrc%2Ftest%2Fjava%2Forg%2Fapache%2Fcamel%2Fconverter%2FStaxConverterTest.java">StaxConverterTest.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Frobobario%2Fcamel">robobario/camel</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="10"> <pre class="line-numbers language-java" data-end="146" data-start="91" data-highlight="125"> public void testEncodingXmlStreamReader() throws Exception { TEST_XML_WITH_XML_HEADER_ISO_8859_1_AS_BYTE_ARRAY_STREAM.reset(); XMLStreamReader reader = null; XMLStreamWriter writer = null; ByteArrayOutputStream output = null; try { // enter text encoded with Latin1 reader = context .getTypeConverter() .mandatoryConvertTo( XMLStreamReader.class, TEST_XML_WITH_XML_HEADER_ISO_8859_1_AS_BYTE_ARRAY_STREAM); output = new ByteArrayOutputStream(); // ensure UTF-8 encoding Exchange exchange = new DefaultExchange(context); exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.name()); writer = context.getTypeConverter().mandatoryConvertTo(XMLStreamWriter.class, exchange, output); // copy to writer while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLEvent.START_DOCUMENT: writer.writeStartDocument(); break; case XMLEvent.END_DOCUMENT: writer.writeEndDocument(); break; case XMLEvent.START_ELEMENT: writer.writeStartElement(reader.getName().getLocalPart()); break; case XMLEvent.CHARACTERS: writer.writeCharacters(reader.getText()); break; case XMLEvent.END_ELEMENT: writer.writeEndElement(); break; default: break; } } } finally { if (reader != null) { reader.close(); } if (writer != null) { writer.close(); } } assertNotNull(output); String result = new String(output.toByteArray(), UTF_8.name()); assertEquals(TEST_XML, result); }</pre> </div> </figure> </div> <div class="example-item" id="0xc9a66b02a8b01f3a7338c2860b2b0bf4f5c6fbd1700665172a62bff4c7c4fb1c-270,,313,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #11</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_11" data-hash="0xc9a66b02a8b01f3a7338c2860b2b0bf4f5c6fbd1700665172a62bff4c7c4fb1c" data-area="270,,313,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '11')" class="rating-up btn btn-success" data-id="rating_11"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'11')" class="rating-down btn btn-danger" data-id="rating_11"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xc9a66b02a8b01f3a7338c2860b2b0bf4f5c6fbd1700665172a62bff4c7c4fb1c-270,,313,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xc9a66b02a8b01f3a7338c2860b2b0bf4f5c6fbd1700665172a62bff4c7c4fb1c&fullName=incf-aba%2Ftrunk%2Fsrc%2Fmain%2Fjava%2Forg%2Fincf%2Faba%2Fatlas%2FGet2DImagesByPOI.java&project=valentinedwv%2Fincf-dai')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvalentinedwv%2Fincf-dai%2Fblob%2Fmaster%2Fincf-aba%2Ftrunk%2Fsrc%2Fmain%2Fjava%2Forg%2Fincf%2Faba%2Fatlas%2FGet2DImagesByPOI.java">Get2DImagesByPOI.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvalentinedwv%2Fincf-dai">valentinedwv/incf-dai</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="11"> <pre class="line-numbers language-java" data-end="313" data-start="271" data-highlight="297,300"> private ImageSeries retrieveImagesSeriesForGene(String geneSymbol, ImageSeriesPlane desiredPlane) throws IOException, XMLStreamException { ImageSeries imageSeries = null; URL u = new URL(ABAUtil.assembleGeneURI(geneSymbol)); LOG.debug("Gene info URI: {}", u.toString()); InputStream in = u.openStream(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader parser = factory.createXMLStreamReader(in); boolean inISid = false; boolean inPlane = false; String isId = null; String plane = null; for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { if (event == XMLStreamConstants.START_ELEMENT) { if (parser.getLocalName().equals("imageseriesid")) { inISid = true; } else if (parser.getLocalName().equals("plane")) { inPlane = true; } } else if (event == XMLStreamConstants.CHARACTERS) { if (inISid) { isId = parser.getText(); inISid = false; } else if (inPlane) { plane = parser.getText(); if (plane.equals(desiredPlane.toString())) { imageSeries = new ImageSeries(isId, desiredPlane); } inPlane = false; } } } try { parser.close(); } catch (XMLStreamException e) { LOG.warn(e.getMessage(), e); // log but go on } return imageSeries; }</pre> </div> </figure> </div> <div class="example-item" id="0x6bf40be168cc735fed1b85f269ad28c394f32e9cc79d2663eb62d0a29915013a-195,,211,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #12</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_12" data-hash="0x6bf40be168cc735fed1b85f269ad28c394f32e9cc79d2663eb62d0a29915013a" data-area="195,,211,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '12')" class="rating-up btn btn-success" data-id="rating_12"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'12')" class="rating-down btn btn-danger" data-id="rating_12"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x6bf40be168cc735fed1b85f269ad28c394f32e9cc79d2663eb62d0a29915013a-195,,211,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x6bf40be168cc735fed1b85f269ad28c394f32e9cc79d2663eb62d0a29915013a&fullName=libraries%2Flttoolbox-java%2Fsrc%2Fmain%2Fjava%2Forg%2Fapertium%2Flttoolbox%2FCompile.java&project=BBAndroidTestApps%2Fmitzuli')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FBBAndroidTestApps%2Fmitzuli%2Fblob%2Fmaster%2Flibraries%2Flttoolbox-java%2Fsrc%2Fmain%2Fjava%2Forg%2Fapertium%2Flttoolbox%2FCompile.java">Compile.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FBBAndroidTestApps%2Fmitzuli">BBAndroidTestApps/mitzuli</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="12"> <pre class="line-numbers language-java" data-end="211" data-start="196" data-highlight="207"> /** * True if all the elements in the current node are blanks * * @return true if all are blanks * @throws javax.xml.stream.XMLStreamException */ private boolean allBlanks() throws XMLStreamException { boolean res = true; if (!reader.hasText()) { return true; } String text = reader.getText(); for (int i = 0, limit = text.length(); i < limit; i++) { res = res && Character.isWhitespace(text.charAt(i)); } return res; }</pre> </div> </figure> </div> <div class="example-item" id="0x5c128097c7e4f821aabe9282b181e10f738daa41d995920796545a63eaaa323b-146,,185,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #13</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_13" data-hash="0x5c128097c7e4f821aabe9282b181e10f738daa41d995920796545a63eaaa323b" data-area="146,,185,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '13')" class="rating-up btn btn-success" data-id="rating_13"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'13')" class="rating-down btn btn-danger" data-id="rating_13"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x5c128097c7e4f821aabe9282b181e10f738daa41d995920796545a63eaaa323b-146,,185,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x5c128097c7e4f821aabe9282b181e10f738daa41d995920796545a63eaaa323b&fullName=XmlParser11.java&project=habedi%2FETLwithHive')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fhabedi%2FETLwithHive%2Fblob%2Fmaster%2FXmlParser11.java">XmlParser11.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fhabedi%2FETLwithHive">habedi/ETLwithHive</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="13"> <pre class="line-numbers language-java" data-end="185" data-start="147" data-highlight="167,170,174"> @Override protected void map(LongWritable key, Text value, Mapper.Context context) throws IOException, InterruptedException { String document = value.toString(); System.out.println("'" + document + "'"); try { XMLStreamReader reader = XMLInputFactory.newInstance() .createXMLStreamReader(new ByteArrayInputStream(document.getBytes())); String propertyName = ""; String propertyValue = ""; String currentElement = ""; while (reader.hasNext()) { int code = reader.next(); switch (code) { case XMLStreamConstants.START_ELEMENT: // START_ELEMENT: currentElement = reader.getLocalName(); break; case XMLStreamConstants.CHARACTERS: // CHARACTERS: if (currentElement.equalsIgnoreCase("uid")) { propertyName += reader.getText().trim(); System.out.println(propertyName); } else if (currentElement.equalsIgnoreCase("location")) { propertyValue += reader.getText().trim(); System.out.println(propertyValue); } else if (currentElement.equalsIgnoreCase("age")) { propertyValue += ("," + reader.getText().trim()); System.out.println(propertyValue); } break; } } reader.close(); context.write(new Text(propertyName.trim()), new Text(propertyValue.trim())); } catch (Exception e) { throw new IOException(e); } }</pre> </div> </figure> </div> <div class="example-item" id="0x0aff6a6203bc4c6af53d438331adc427b9f68cd9618f95e86faebebfefed5b10-147,,185,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #14</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_14" data-hash="0x0aff6a6203bc4c6af53d438331adc427b9f68cd9618f95e86faebebfefed5b10" data-area="147,,185,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '14')" class="rating-up btn btn-success" data-id="rating_14"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'14')" class="rating-down btn btn-danger" data-id="rating_14"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x0aff6a6203bc4c6af53d438331adc427b9f68cd9618f95e86faebebfefed5b10-147,,185,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x0aff6a6203bc4c6af53d438331adc427b9f68cd9618f95e86faebebfefed5b10&fullName=src%2Fcom%2Ferwandano%2Ffsdiff%2FFSHXLoadTask.java&project=Braincoke%2FFSDiff')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FBraincoke%2FFSDiff%2Fblob%2Fmaster%2Fsrc%2Fcom%2Ferwandano%2Ffsdiff%2FFSHXLoadTask.java">FSHXLoadTask.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FBraincoke%2FFSDiff">Braincoke/FSDiff</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="14"> <pre class="line-numbers language-java" data-end="185" data-start="148" data-highlight="167,170"> public HashedFile loadHashedFile() throws XMLStreamException { String endTag = "file"; Path path = Paths.get(""); String md5 = ""; int type; String currentElement; boolean done = false; while (!done && reader.hasNext()) { type = reader.next(); if (type == XMLStreamReader.END_ELEMENT) { done = reader.getLocalName().compareTo(endTag) == 0; } else if (type == XMLStreamReader.START_ELEMENT) { currentElement = reader.getLocalName(); do { type = reader.next(); } while (type != XMLStreamReader.CHARACTERS && type != XMLStreamReader.END_ELEMENT); if (type == XMLStreamReader.CHARACTERS) { switch (currentElement) { case "md5": md5 = reader.getText(); break; case "filePath": path = Paths.get(reader.getText()); break; } // Look for the end of the current element and throw an exception if it cannot be found do { type = reader.next(); } while (type != XMLStreamReader.END_ELEMENT); verifyClosing(currentElement); } else { verifyClosing(currentElement); } } } HashedFile result = new HashedFile(path); result.setMd5(md5); return result; }</pre> </div> </figure> </div> <div class="example-item" id="0xd809224084d8acd4544f6e7119a136fc143f67e58bcb21277e84023d4017ec79-121,,134,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #15</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_15" data-hash="0xd809224084d8acd4544f6e7119a136fc143f67e58bcb21277e84023d4017ec79" data-area="121,,134,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '15')" class="rating-up btn btn-success" data-id="rating_15"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'15')" class="rating-down btn btn-danger" data-id="rating_15"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xd809224084d8acd4544f6e7119a136fc143f67e58bcb21277e84023d4017ec79-121,,134,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xd809224084d8acd4544f6e7119a136fc143f67e58bcb21277e84023d4017ec79&fullName=src%2Ftest%2Fjava%2Forg%2Fcodehaus%2FStaxMateTestBase.java&project=tblong%2FStaxMate')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Ftblong%2FStaxMate%2Fblob%2Fmaster%2Fsrc%2Ftest%2Fjava%2Forg%2Fcodehaus%2FStaxMateTestBase.java">StaxMateTestBase.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Ftblong%2FStaxMate">tblong/StaxMate</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="15"> <pre class="line-numbers language-java" data-end="134" data-start="122" data-highlight="128"> /** Note: calling this method will move stream to the next non-textual event. */ protected String collectAllText(XMLStreamReader sr) throws XMLStreamException { StringBuilder sb = new StringBuilder(100); while (true) { int type = sr.getEventType(); if (type == CHARACTERS || type == SPACE || type == CDATA) { sb.append(sr.getText()); sr.next(); } else { break; } } return sb.toString(); }</pre> </div> </figure> </div> <div class="example-item" id="0x318789271a1ced1153fc0a95c4e79c87e4a0ee8f6a0e4c7765819a80af896878-35,,83,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #16</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_16" data-hash="0x318789271a1ced1153fc0a95c4e79c87e4a0ee8f6a0e4c7765819a80af896878" data-area="35,,83,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '16')" class="rating-up btn btn-success" data-id="rating_16"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'16')" class="rating-down btn btn-danger" data-id="rating_16"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x318789271a1ced1153fc0a95c4e79c87e4a0ee8f6a0e4c7765819a80af896878-35,,83,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x318789271a1ced1153fc0a95c4e79c87e4a0ee8f6a0e4c7765819a80af896878&fullName=src%2Fby%2Fhtp%2Fxml%2FService.java&project=quitedeimos%2FXML')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fquitedeimos%2FXML%2Fblob%2Fmaster%2Fsrc%2Fby%2Fhtp%2Fxml%2FService.java">Service.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fquitedeimos%2FXML">quitedeimos/XML</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="16"> <pre class="line-numbers language-java" data-end="83" data-start="36" data-highlight="58"> @SuppressWarnings("incomplete-switch") public List<Weapon> parseByStAX() throws FileNotFoundException, XMLStreamException { List<Weapon> listWeapon = new ArrayList<Weapon>(); Weapon weapon = null; WeaponTagName elementName = null; XMLInputFactory inputFactory = XMLInputFactory.newInstance(); InputStream input = new FileInputStream("resources/weaponMarket.xml"); XMLStreamReader reader = inputFactory.createXMLStreamReader(input); while (reader.hasNext()) { int type = reader.next(); switch (type) { case XMLStreamConstants.START_ELEMENT: elementName = WeaponTagName.valueOf(reader.getLocalName().toUpperCase().replace("-", "_")); switch (elementName) { case WEAPON: weapon = new Weapon(); weapon.setId(reader.getAttributeValue(null, "id")); break; } break; case XMLStreamConstants.CHARACTERS: String text = reader.getText().trim(); if (text.isEmpty()) { break; } switch (elementName) { case WEAPON_TYPE: weapon.setWeaponType(text); break; case WEAPON_NAME: weapon.setWeaponName(text); break; case COST: weapon.setCost(text); break; } break; case XMLStreamConstants.END_ELEMENT: elementName = WeaponTagName.valueOf(reader.getLocalName().toUpperCase().replace("-", "_")); switch (elementName) { case WEAPON: listWeapon.add(weapon); } } } return listWeapon; }</pre> </div> </figure> </div> <div class="example-item" id="0xf030d20bf926839fd58fb4b6a4be2513363746795044af7d5f8a587e2e7f2b25-51,,74,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #17</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_17" data-hash="0xf030d20bf926839fd58fb4b6a4be2513363746795044af7d5f8a587e2e7f2b25" data-area="51,,74,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '17')" class="rating-up btn btn-success" data-id="rating_17"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'17')" class="rating-down btn btn-danger" data-id="rating_17"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xf030d20bf926839fd58fb4b6a4be2513363746795044af7d5f8a587e2e7f2b25-51,,74,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xf030d20bf926839fd58fb4b6a4be2513363746795044af7d5f8a587e2e7f2b25&fullName=src%2Fmain%2Fjava%2Fuk%2Fac%2Fsusx%2Ftag%2Fdialoguer%2Fknowledge%2Fdatabase%2Fproduct%2Fcollections%2Fxml%2FMusicCollection.java&project=andehr%2Ftag-dialogue-framework')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fandehr%2Ftag-dialogue-framework%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Fuk%2Fac%2Fsusx%2Ftag%2Fdialoguer%2Fknowledge%2Fdatabase%2Fproduct%2Fcollections%2Fxml%2FMusicCollection.java">MusicCollection.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fandehr%2Ftag-dialogue-framework">andehr/tag-dialogue-framework</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="17"> <pre class="line-numbers language-java" data-end="74" data-start="52" data-highlight="68,69"> private void readRecord(XMLStreamReader reader) throws XMLStreamException { String currentKey = null; if (isStartElement("record")) { while (reader.hasNext() && !isEndElement("record")) { reader.next(); if (reader.isStartElement()) { if (reader.getLocalName().equals("contributor_list")) { contributorList = readBasicRecords(reader, "person", "contributor_list"); currentKey = null; } else if (reader.getLocalName().equals("tracklist")) { trackList = readBasicRecords(reader, "track_details", "tracklist"); currentKey = null; } else { currentKey = reader.getLocalName(); } } else if (reader.isCharacters()) { if (currentKey != null && !reader.getText().trim().equals("")) { atts.put(currentKey, reader.getText()); currentKey = null; } } } } else throw new IllegalStateException("Reader is not at the start of a record"); }</pre> </div> </figure> </div> <div class="example-item" id="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-267,,321,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #18</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_18" data-hash="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4" data-area="267,,321,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '18')" class="rating-up btn btn-success" data-id="rating_18"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'18')" class="rating-down btn btn-danger" data-id="rating_18"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-267,,321,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4&fullName=src%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java&project=jbartece%2Fundertow4jenkins')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins%2Fblob%2Fmaster%2Fsrc%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java">WebXmlParser.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins">jbartece/undertow4jenkins</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="18"> <pre class="line-numbers language-java" data-end="321" data-start="268" data-highlight="285"> // <login-config> // <auth-method>FORM</auth-method> // <form-login-config> // <form-login-page>/login</form-login-page> // <form-error-page>/loginError</form-error-page> // </form-login-config> // </login-config> private LoginConfig loadLoginConfig(XMLStreamReader xmlReader) throws WebXmlFormatException, XMLStreamException { String tagContent = null; String tagName; LoginConfig loginConfig = new LoginConfig(); while (xmlReader.hasNext()) { switch (xmlReader.next()) { case XMLStreamConstants.CHARACTERS: tagContent = xmlReader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: tagName = xmlReader.getLocalName(); if (tagName.equals("auth-method")) { loginConfig.authMethod = tagContent; continue; } if (tagName.equals("form-login-page")) { loginConfig.formLoginPage = tagContent; continue; } if (tagName.equals("form-error-page")) { loginConfig.formErrorPage = tagContent; continue; } if (tagName.equals("form-login-config")) { if (loginConfig.formLoginPage == null || loginConfig.formErrorPage == null) throwMalformedWebXml("Login-config"); } if (tagName.equals("login-config")) { return loginConfig; } default: break; } } throwMalformedWebXml("Login-config"); return null; // Never happens. Method above always throws exception }</pre> </div> </figure> </div> <div class="example-item" id="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-215,,265,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #19</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_19" data-hash="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4" data-area="215,,265,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '19')" class="rating-up btn btn-success" data-id="rating_19"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'19')" class="rating-down btn btn-danger" data-id="rating_19"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-215,,265,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4&fullName=src%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java&project=jbartece%2Fundertow4jenkins')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins%2Fblob%2Fmaster%2Fsrc%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java">WebXmlParser.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins">jbartece/undertow4jenkins</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="19"> <pre class="line-numbers language-java" data-end="265" data-start="216" data-highlight="231"> // <env-entry> // <env-entry-name>HUDSON_HOME</env-entry-name> // <env-entry-type>java.lang.String</env-entry-type> // <env-entry-value></env-entry-value> // </env-entry> private EnvEntry loadEnvEntry(XMLStreamReader xmlReader) throws WebXmlFormatException, XMLStreamException { String tagContent = null; String tagName; EnvEntry envEntry = new EnvEntry(); while (xmlReader.hasNext()) { switch (xmlReader.next()) { case XMLStreamConstants.CHARACTERS: tagContent = xmlReader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: tagName = xmlReader.getLocalName(); if (tagName.equals("env-entry-name")) { envEntry.entryName = tagContent; continue; } if (tagName.equals("env-entry-type")) { envEntry.entryType = tagContent; continue; } if (tagName.equals("env-entry-value")) { envEntry.entryValue = tagContent; continue; } if (tagName.equals("env-entry")) { if (envEntry.entryName == null || envEntry.entryValue == null || envEntry.entryType == null) throwMalformedWebXml("Env-entry"); else return envEntry; } default: break; } } throwMalformedWebXml("Env-entry"); return null; // Never happens. Method above always throws exception }</pre> </div> </figure> </div> <div class="example-item" id="0xaed0948acd03a7148fdc3dbebc7ec06dbff1288e3bec889a5ed16d18e7af13f3-70,,89,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #20</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_20" data-hash="0xaed0948acd03a7148fdc3dbebc7ec06dbff1288e3bec889a5ed16d18e7af13f3" data-area="70,,89,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '20')" class="rating-up btn btn-success" data-id="rating_20"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'20')" class="rating-down btn btn-danger" data-id="rating_20"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xaed0948acd03a7148fdc3dbebc7ec06dbff1288e3bec889a5ed16d18e7af13f3-70,,89,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xaed0948acd03a7148fdc3dbebc7ec06dbff1288e3bec889a5ed16d18e7af13f3&fullName=grobid-ner%2Fsrc%2Fmain%2Fjava%2Forg%2Fgrobid%2Ftrainer%2FStaxUtils.java&project=kermitt2%2Fgrobid-ner')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fkermitt2%2Fgrobid-ner%2Fblob%2Fmaster%2Fgrobid-ner%2Fsrc%2Fmain%2Fjava%2Forg%2Fgrobid%2Ftrainer%2FStaxUtils.java">StaxUtils.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fkermitt2%2Fgrobid-ner">kermitt2/grobid-ner</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="20"> <pre class="line-numbers language-java" data-end="89" data-start="71" data-highlight="83"> public static Map<String, String> parse( XMLStreamReader streamReader, EndCondition endCondition, String... tags) throws XMLStreamException { Map<String, String> mapping = new HashMap<String, String>(); while (streamReader.hasNext() && !endCondition.mustExit(streamReader)) { streamReader.next(); if (XMLStreamReader.START_ELEMENT == streamReader.getEventType()) { String localPart = streamReader.getName().getLocalPart(); for (String tag : tags) { if (tag.equals(localPart)) { streamReader.next(); if (XMLStreamReader.CHARACTERS == streamReader.getEventType()) { mapping.put(tag, streamReader.getText()); } } } } } return mapping; }</pre> </div> </figure> </div> <div class="example-item" id="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-578,,622,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #21</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_21" data-hash="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4" data-area="578,,622,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '21')" class="rating-up btn btn-success" data-id="rating_21"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'21')" class="rating-down btn btn-danger" data-id="rating_21"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-578,,622,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4&fullName=src%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java&project=jbartece%2Fundertow4jenkins')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins%2Fblob%2Fmaster%2Fsrc%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java">WebXmlParser.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins">jbartece/undertow4jenkins</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="21"> <pre class="line-numbers language-java" data-end="622" data-start="579" data-highlight="593"> // <servlet-mapping> // <servlet-name>Stapler</servlet-name> // <url-pattern>/*</url-pattern> // </servlet-mapping> private ServletMapping loadServletMapping(XMLStreamReader xmlReader) throws WebXmlFormatException, XMLStreamException { String tagContent = null; String tagName; ServletMapping servletMapping = new ServletMapping(); while (xmlReader.hasNext()) { switch (xmlReader.next()) { case XMLStreamConstants.CHARACTERS: tagContent = xmlReader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: tagName = xmlReader.getLocalName(); if (tagName.equals("servlet-name")) { servletMapping.servletName = tagContent; continue; } if (tagName.equals("url-pattern")) { servletMapping.urlPattern = tagContent; continue; } if (tagName.equals("servlet-mapping")) { if (servletMapping.servletName == null || servletMapping.urlPattern == null) throwExceptionNotSpecifiedParameter("Servlet-mapping", "servlet-name", "url-pattern"); else return servletMapping; } break; default: break; } } throwMalformedWebXml("servlet-mapping"); return null; // Never happens. Method above always throws exception }</pre> </div> </figure> </div> <div class="example-item" id="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-532,,576,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #22</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_22" data-hash="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4" data-area="532,,576,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '22')" class="rating-up btn btn-success" data-id="rating_22"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'22')" class="rating-down btn btn-danger" data-id="rating_22"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-532,,576,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4&fullName=src%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java&project=jbartece%2Fundertow4jenkins')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins%2Fblob%2Fmaster%2Fsrc%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java">WebXmlParser.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins">jbartece/undertow4jenkins</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="22"> <pre class="line-numbers language-java" data-end="576" data-start="533" data-highlight="547"> // <filter> // <filter-name>encoding-filter</filter-name> // <filter-class>hudson.util.CharacterEncodingFilter</filter-class> // </filter> private Filter loadFilter(XMLStreamReader xmlReader) throws WebXmlFormatException, XMLStreamException { String tagContent = null; String tagName; Filter filter = new Filter(); while (xmlReader.hasNext()) { switch (xmlReader.next()) { case XMLStreamConstants.CHARACTERS: tagContent = xmlReader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: tagName = xmlReader.getLocalName(); if (tagName.equals("filter-name")) { filter.filterName = tagContent; continue; } if (tagName.equals("filter-class")) { filter.filterClass = tagContent; continue; } if (tagName.equals("filter")) { if (filter.filterName == null || filter.filterClass == null) throwExceptionNotSpecifiedParameter("Filter", "filter-name", "filter-class"); else return filter; } break; default: break; } } throwMalformedWebXml("filter"); return null; // Never happens. Method above always throws exception }</pre> </div> </figure> </div> <div class="example-item" id="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-125,,168,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #23</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_23" data-hash="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4" data-area="125,,168,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '23')" class="rating-up btn btn-success" data-id="rating_23"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'23')" class="rating-down btn btn-danger" data-id="rating_23"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-125,,168,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4&fullName=src%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java&project=jbartece%2Fundertow4jenkins')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins%2Fblob%2Fmaster%2Fsrc%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java">WebXmlParser.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins">jbartece/undertow4jenkins</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="23"> <pre class="line-numbers language-java" data-end="168" data-start="126" data-highlight="140"> // <error-page> // <exception-type>java.lang.Throwable</exception-type> // <location>/oops</location> // </error-page> private ErrorPage loadErrorPage(XMLStreamReader xmlReader) throws WebXmlFormatException, XMLStreamException { String tagContent = null; String tagName; ErrorPage errorPage = new ErrorPage(); while (xmlReader.hasNext()) { switch (xmlReader.next()) { case XMLStreamConstants.CHARACTERS: tagContent = xmlReader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: tagName = xmlReader.getLocalName(); if (tagName.equals("exception-type")) { errorPage.exceptionType = tagContent; continue; } if (tagName.equals("location")) { errorPage.location = tagContent; continue; } if (tagName.equals("error-page")) { if (errorPage.exceptionType == null || errorPage.location == null) throwMalformedWebXml("Error-page"); else return errorPage; } default: break; } } throwMalformedWebXml("Error-page"); return null; // Never happens. Method above always throws exception }</pre> </div> </figure> </div> <div class="example-item" id="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-170,,213,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #24</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_24" data-hash="0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4" data-area="170,,213,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '24')" class="rating-up btn btn-success" data-id="rating_24"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'24')" class="rating-down btn btn-danger" data-id="rating_24"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4-170,,213,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x60389663c4b0eeba34a093d4d4a5b67c68bd3fc77c47db9bdcaf16c01ac734e4&fullName=src%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java&project=jbartece%2Fundertow4jenkins')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins%2Fblob%2Fmaster%2Fsrc%2Fsrc%2Fmain%2Fjava%2Fundertow4jenkins%2FWebXmlParser.java">WebXmlParser.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjbartece%2Fundertow4jenkins">jbartece/undertow4jenkins</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="24"> <pre class="line-numbers language-java" data-end="213" data-start="171" data-highlight="185"> // <mime-mapping> // <extension>webm</extension> // <mime-type>video/webm</mime-type> // </mime-mapping> private MimeMapping loadMimeMapping(XMLStreamReader xmlReader) throws WebXmlFormatException, XMLStreamException { String tagContent = null; String tagName; MimeMapping mimeMapping = new MimeMapping(); while (xmlReader.hasNext()) { switch (xmlReader.next()) { case XMLStreamConstants.CHARACTERS: tagContent = xmlReader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: tagName = xmlReader.getLocalName(); if (tagName.equals("extension")) { mimeMapping.extension = tagContent; continue; } if (tagName.equals("mime-type")) { mimeMapping.mimeType = tagContent; continue; } if (tagName.equals("mime-mapping")) { if (mimeMapping.extension == null || mimeMapping.mimeType == null) throwMalformedWebXml("Mime-mapping"); else return mimeMapping; } default: break; } } throwMalformedWebXml("Mime-mapping"); return null; // Never happens. Method above always throws exception }</pre> </div> </figure> </div> <div class="example-item" id="0x8ecd622af4387f2fd85b1f64ef33cc5ab80559f05e5ebd6783c55200079d1ef3-46,,67,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #25</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_25" data-hash="0x8ecd622af4387f2fd85b1f64ef33cc5ab80559f05e5ebd6783c55200079d1ef3" data-area="46,,67,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '25')" class="rating-up btn btn-success" data-id="rating_25"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'25')" class="rating-down btn btn-danger" data-id="rating_25"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0x8ecd622af4387f2fd85b1f64ef33cc5ab80559f05e5ebd6783c55200079d1ef3-46,,67,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0x8ecd622af4387f2fd85b1f64ef33cc5ab80559f05e5ebd6783c55200079d1ef3&fullName=src%2Fcom%2Fxml%2FUnknownStructureXmlParser.java&project=olegbezk%2FParseUnknownXML')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Folegbezk%2FParseUnknownXML%2Fblob%2Fmaster%2Fsrc%2Fcom%2Fxml%2FUnknownStructureXmlParser.java">UnknownStructureXmlParser.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Folegbezk%2FParseUnknownXML">olegbezk/ParseUnknownXML</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="25"> <pre class="line-numbers language-java" data-end="67" data-start="47" data-highlight="60"> public Map<String, String> parse(File file) throws Exception { Map<String, String> map = new HashMap<>(); XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream(file)); while (xr.hasNext()) { int e = xr.next(); if (e == XMLStreamReader.START_ELEMENT) { String name = xr.getLocalName(); xr.next(); String value = null; try { value = xr.getText(); } catch (IllegalStateException ex) { logger.warn(ex); } map.put(name, value); } } return map; }</pre> </div> </figure> </div> <div class="example-item" id="0xe746e0c0a730487d0745c2ae29ea33efa4315b3fdfe8dd03382ad60e40938749-663,,751,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #26</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_26" data-hash="0xe746e0c0a730487d0745c2ae29ea33efa4315b3fdfe8dd03382ad60e40938749" data-area="663,,751,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '26')" class="rating-up btn btn-success" data-id="rating_26"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'26')" class="rating-down btn btn-danger" data-id="rating_26"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xe746e0c0a730487d0745c2ae29ea33efa4315b3fdfe8dd03382ad60e40938749-663,,751,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xe746e0c0a730487d0745c2ae29ea33efa4315b3fdfe8dd03382ad60e40938749&fullName=core%2Fsrc%2Fmain%2Fjava%2Forg%2FStaxNavigatorImpl.java&project=mto%2Fstaxnav')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fmto%2Fstaxnav%2Fblob%2Fmaster%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2FStaxNavigatorImpl.java">StaxNavigatorImpl.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fmto%2Fstaxnav">mto/staxnav</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="26"> <pre class="line-numbers language-java" data-end="751" data-start="664" data-highlight="723,728"> private Element(XMLStreamReader stream, Element parent) throws XMLStreamException { // We assume that the stream points to the start of the modelled element if (stream.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new AssertionError(); } // QName name = stream.getName(); Location location = stream.getLocation(); // Map<String, String> attributes = Collections.emptyMap(); Map<QName, String> qualifiedAttributes = Collections.emptyMap(); int attributeCount = stream.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { String attributeValue = stream.getAttributeValue(i); QName attributeName = stream.getAttributeName(i); if (XMLConstants.NULL_NS_URI.equals(attributeName.getNamespaceURI())) { if (attributes.isEmpty()) { attributes = new HashMap<String, String>(); } attributes.put(attributeName.getLocalPart(), attributeValue); } else { if (qualifiedAttributes.isEmpty()) { qualifiedAttributes = new HashMap<QName, String>(); } qualifiedAttributes.put(attributeName, attributeValue); } } // Map<String, String> namespaces; int namespaceCount = stream.getNamespaceCount(); if (namespaceCount > 0) { namespaces = new HashMap<String, String>(); for (int i = 0; i < namespaceCount; i++) { String namespacePrefix = stream.getNamespacePrefix(i); if (namespacePrefix == null) { namespacePrefix = ""; } String namespaceURI = stream.getNamespaceURI(i); namespaces.put(namespacePrefix, namespaceURI); } } else { namespaces = Collections.emptyMap(); } // When we leave we assume that we are positionned on the next element start or the document // end StringBuilder sb = null; String chunk = null; Object content = null; while (true) { stream.next(); int type = stream.getEventType(); if (type == XMLStreamConstants.END_DOCUMENT || type == XMLStreamConstants.START_ELEMENT) { break; } else if (type == XMLStreamConstants.CHARACTERS) { if (chunk == null) { chunk = stream.getText(); } else { if (sb == null) { sb = new StringBuilder(chunk); } sb.append(stream.getText()); } } else if (type == XMLStreamConstants.END_ELEMENT) { if (sb != null) { content = sb; } else { content = chunk; } break; } } // int depth = 1 + (parent != null ? parent.getDepth() : 0); // this.parent = parent; this.name = name; this.depth = depth; this.content = content; this.attributes = attributes; this.qualifiedAttributes = qualifiedAttributes; this.namespaces = namespaces; this.location = location; }</pre> </div> </figure> </div> <div class="example-item" id="0xe160346aaaec1f063a30f1add5796d9738ddbaf0a509b708d28dbe2b53d7fb5d-240,,242,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #27</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_27" data-hash="0xe160346aaaec1f063a30f1add5796d9738ddbaf0a509b708d28dbe2b53d7fb5d" data-area="240,,242,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '27')" class="rating-up btn btn-success" data-id="rating_27"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'27')" class="rating-down btn btn-danger" data-id="rating_27"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xe160346aaaec1f063a30f1add5796d9738ddbaf0a509b708d28dbe2b53d7fb5d-240,,242,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xe160346aaaec1f063a30f1add5796d9738ddbaf0a509b708d28dbe2b53d7fb5d&fullName=src%2Fmain%2Fjava%2Forg%2Fjboss%2FXMLExtendedStreamReaderImpl.java&project=stalep%2Fstaxmapper')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fstalep%2Fstaxmapper%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Forg%2Fjboss%2FXMLExtendedStreamReaderImpl.java">XMLExtendedStreamReaderImpl.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fstalep%2Fstaxmapper">stalep/staxmapper</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="27"> <pre class="line-numbers language-java" data-end="242" data-start="241" data-highlight="242"> public String getText() { return streamReader.getText(); }</pre> </div> </figure> </div> <div class="example-item" id="0xd3ee4dec96fb1203363e741d16f8b2b441737a9481ef89888afb40ed0f69aeaa-246,,315,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #28</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_28" data-hash="0xd3ee4dec96fb1203363e741d16f8b2b441737a9481ef89888afb40ed0f69aeaa" data-area="246,,315,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '28')" class="rating-up btn btn-success" data-id="rating_28"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'28')" class="rating-down btn btn-danger" data-id="rating_28"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xd3ee4dec96fb1203363e741d16f8b2b441737a9481ef89888afb40ed0f69aeaa-246,,315,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xd3ee4dec96fb1203363e741d16f8b2b441737a9481ef89888afb40ed0f69aeaa&fullName=src%2Fjava%2Forg%2Fapache%2Fsolr%2FXMLLoader.java&project=Photobucket%2FSolbase-Solr')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FPhotobucket%2FSolbase-Solr%2Fblob%2Fmaster%2Fsrc%2Fjava%2Forg%2Fapache%2Fsolr%2FXMLLoader.java">XMLLoader.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FPhotobucket%2FSolbase-Solr">Photobucket/Solbase-Solr</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="28"> <pre class="line-numbers language-java" data-end="315" data-start="247" data-highlight="276"> /** * Given the input stream, read a document * * @since solr 1.3 */ SolrInputDocument readDoc(XMLStreamReader parser) throws XMLStreamException { SolrInputDocument doc = new SolrInputDocument(); String attrName = ""; for (int i = 0; i < parser.getAttributeCount(); i++) { attrName = parser.getAttributeLocalName(i); if ("boost".equals(attrName)) { doc.setDocumentBoost(Float.parseFloat(parser.getAttributeValue(i))); } else { XmlUpdateRequestHandler.log.warn("Unknown attribute doc/@" + attrName); } } StringBuilder text = new StringBuilder(); String name = null; float boost = 1.0f; boolean isNull = false; while (true) { int event = parser.next(); switch (event) { // Add everything to the text case XMLStreamConstants.SPACE: case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: text.append(parser.getText()); break; case XMLStreamConstants.END_ELEMENT: if ("doc".equals(parser.getLocalName())) { return doc; } else if ("field".equals(parser.getLocalName())) { if (!isNull) { doc.addField(name, text.toString(), boost); boost = 1.0f; } } break; case XMLStreamConstants.START_ELEMENT: text.setLength(0); String localName = parser.getLocalName(); if (!"field".equals(localName)) { XmlUpdateRequestHandler.log.warn("unexpected XML tag doc/" + localName); throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unexpected XML tag doc/" + localName); } boost = 1.0f; String attrVal = ""; for (int i = 0; i < parser.getAttributeCount(); i++) { attrName = parser.getAttributeLocalName(i); attrVal = parser.getAttributeValue(i); if ("name".equals(attrName)) { name = attrVal; } else if ("boost".equals(attrName)) { boost = Float.parseFloat(attrVal); } else if ("null".equals(attrName)) { isNull = StrUtils.parseBoolean(attrVal); } else { XmlUpdateRequestHandler.log.warn("Unknown attribute doc/field/@" + attrName); } } break; } } }</pre> </div> </figure> </div> <div class="example-item" id="0xd3ee4dec96fb1203363e741d16f8b2b441737a9481ef89888afb40ed0f69aeaa-179,,244,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #29</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_29" data-hash="0xd3ee4dec96fb1203363e741d16f8b2b441737a9481ef89888afb40ed0f69aeaa" data-area="179,,244,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '29')" class="rating-up btn btn-success" data-id="rating_29"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'29')" class="rating-down btn btn-danger" data-id="rating_29"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xd3ee4dec96fb1203363e741d16f8b2b441737a9481ef89888afb40ed0f69aeaa-179,,244,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xd3ee4dec96fb1203363e741d16f8b2b441737a9481ef89888afb40ed0f69aeaa&fullName=src%2Fjava%2Forg%2Fapache%2Fsolr%2FXMLLoader.java&project=Photobucket%2FSolbase-Solr')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FPhotobucket%2FSolbase-Solr%2Fblob%2Fmaster%2Fsrc%2Fjava%2Forg%2Fapache%2Fsolr%2FXMLLoader.java">XMLLoader.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FPhotobucket%2FSolbase-Solr">Photobucket/Solbase-Solr</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="29"> <pre class="line-numbers language-java" data-end="244" data-start="180" data-highlight="241"> /** @since solr 1.3 */ void processDelete(UpdateRequestProcessor processor, XMLStreamReader parser, SolrParams params) throws XMLStreamException, IOException { // Parse the command DeleteUpdateCommand deleteCmd = new DeleteUpdateCommand(); deleteCmd.fromPending = true; deleteCmd.fromCommitted = true; Boolean updateStore = params.getBool(UpdateParams.UPDATE_STORE); if (updateStore != null) { deleteCmd.setUpdateStore(updateStore.booleanValue()); } for (int i = 0; i < parser.getAttributeCount(); i++) { String attrName = parser.getAttributeLocalName(i); String attrVal = parser.getAttributeValue(i); if ("fromPending".equals(attrName)) { deleteCmd.fromPending = StrUtils.parseBoolean(attrVal); } else if ("fromCommitted".equals(attrName)) { deleteCmd.fromCommitted = StrUtils.parseBoolean(attrVal); } else { XmlUpdateRequestHandler.log.warn("unexpected attribute delete/@" + attrName); } } StringBuilder text = new StringBuilder(); while (true) { int event = parser.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: String mode = parser.getLocalName(); if (!("id".equals(mode) || "query".equals(mode))) { XmlUpdateRequestHandler.log.warn("unexpected XML tag /delete/" + mode); throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unexpected XML tag /delete/" + mode); } text.setLength(0); break; case XMLStreamConstants.END_ELEMENT: String currTag = parser.getLocalName(); if ("id".equals(currTag)) { deleteCmd.id = text.toString(); } else if ("query".equals(currTag)) { deleteCmd.query = text.toString(); } else if ("delete".equals(currTag)) { return; } else { XmlUpdateRequestHandler.log.warn("unexpected XML tag /delete/" + currTag); throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unexpected XML tag /delete/" + currTag); } processor.processDelete(deleteCmd); deleteCmd.id = null; deleteCmd.query = null; break; // Add everything to the text case XMLStreamConstants.SPACE: case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: text.append(parser.getText()); break; } } }</pre> </div> </figure> </div> <div class="example-item" id="0xc9a66b02a8b01f3a7338c2860b2b0bf4f5c6fbd1700665172a62bff4c7c4fb1c-376,,445,"> <div class="bs-example"> <div> <div class="bs-example-title">Example #30</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_30" data-hash="0xc9a66b02a8b01f3a7338c2860b2b0bf4f5c6fbd1700665172a62bff4c7c4fb1c" data-area="376,,445,"> <div class="rating-amount">0</div> <a title="Mark this example as good" href="javascript:app.addRating(1, '30')" class="rating-up btn btn-success" data-id="rating_30"><i class="icon-button icon-thumbs-up"></i></a> <a title="Mark this example as bad" href="javascript:app.addRating(-1,'30')" class="rating-down btn btn-danger" data-id="rating_30"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="Direct link to this example" href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html#0xc9a66b02a8b01f3a7338c2860b2b0bf4f5c6fbd1700665172a62bff4c7c4fb1c-376,,445,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://java.hotexamples.com/site/file?hash=0xc9a66b02a8b01f3a7338c2860b2b0bf4f5c6fbd1700665172a62bff4c7c4fb1c&fullName=incf-aba%2Ftrunk%2Fsrc%2Fmain%2Fjava%2Forg%2Fincf%2Faba%2Fatlas%2FGet2DImagesByPOI.java&project=valentinedwv%2Fincf-dai')">Show file</a> </div> <div class="example-project-info"> <nobr> <span>File:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvalentinedwv%2Fincf-dai%2Fblob%2Fmaster%2Fincf-aba%2Ftrunk%2Fsrc%2Fmain%2Fjava%2Forg%2Fincf%2Faba%2Fatlas%2FGet2DImagesByPOI.java">Get2DImagesByPOI.java</a> </nobr> <nobr> <span>Project:</span> <a target="_blank" rel="nofollow" href="https://java.hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvalentinedwv%2Fincf-dai">valentinedwv/incf-dai</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="30"> <pre class="line-numbers language-java" data-end="445" data-start="377" data-highlight="413,416,419,425,430"> private void retrieveImageForPosition(String imageSeriesId, String position, Image image) throws IOException, XMLStreamException { URL u = new URL(assembleImageSeriesURI(imageSeriesId)); LOG.debug("Meta info URI: {}", u.toString()); InputStream in = u.openStream(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader parser = factory.createXMLStreamReader(in); boolean inImDisplayName = false; boolean inImId = false; boolean inPosition = false; boolean inThumbnailurl = false; boolean inDownloadImagePath = false; boolean positionMatch = false; for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { if (event == XMLStreamConstants.START_ELEMENT) { if (parser.getLocalName().equals("imagedisplayname")) { inImDisplayName = true; } else if (parser.getLocalName().equals("imageid")) { inImId = true; } else if (parser.getLocalName().equals("position")) { inPosition = true; } else if (parser.getLocalName().equals("thumbnailurl")) { inThumbnailurl = true; } else if (parser.getLocalName().equals("downloadImagePath")) { inDownloadImagePath = true; } } else if (event == XMLStreamConstants.CHARACTERS) { // element sequence is significant! imagedisplayname and // imageid precede position which is match value if (inImDisplayName) { image.imagedisplayname = parser.getText(); inImDisplayName = false; } else if (inImId) { image.imageId = parser.getText(); inImId = false; } else if (inPosition) { if (parser.getText().equals(position)) { positionMatch = true; } inPosition = false; } else if (inThumbnailurl) { if (positionMatch) { image.thumbnailurl = parser.getText(); } inThumbnailurl = false; } else if (inDownloadImagePath) { if (positionMatch) { image.downloadImagePath = parser.getText(); break; } inDownloadImagePath = false; } } } try { parser.close(); } catch (XMLStreamException e) { LOG.warn(e.getMessage(), e); // log but go on } LOG.debug( "imageId: {}\n thumbnailurl: {}\n downloadImagePath: {}", new String[] {image.imageId, image.thumbnailurl, image.downloadImagePath}); }</pre> </div> </figure> </div> <div id="all-examples"></div> </div> </div> </div> <div class="page-side-banner hidden-xs hidden-sm hidden-md" style="width:300px"> <div id="ezoic-pub-ad-placeholder-131"> <div class="fx" style="width:300px"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- right-sidebar-fx --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="8968655429" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> </div> </div> </div> <footer class="footer"> <div class="container"> <div class="row"> <div class="col-md-12" style="text-align: center"> <a href="https://java.hotexamples.com/site/trends?type=java%7Cc"> Top Classes </a> | <a href="/site/privacy">Privacy Policy</a> | <a href="https://cpp.hotexamples.com/direct-sales.html">Advertise with us</a> </div> </div> <div class="row"> <div class="col-md-12" style="text-align: center"> <a href="https://hotexamples.com/">PHP</a> | <a href="https://csharp.hotexamples.com/">C# (CSharp)</a> | <a href="https://java.hotexamples.com/">Java</a> | <a href="https://golang.hotexamples.com/">Golang</a> | <a href="https://cpp.hotexamples.com/">C++ (Cpp)</a> | <a href="https://python.hotexamples.com/">Python</a> | <a href="https://javascript.hotexamples.com/">JavaScript</a> | <a href="https://typescript.hotexamples.com/">TypeScript</a> </div> </div> <div class="row"> <div class="col-md-12" style="text-align: center"> <a href="https://java.hotexamples.com/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">EN</a> | <a href="https://java.hotexamples.com/ru/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">RU</a> | <a href="https://java.hotexamples.com/de/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">DE</a> | <a href="https://java.hotexamples.com/fr/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">FR</a> | <a href="https://java.hotexamples.com/es/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">ES</a> | <a href="https://java.hotexamples.com/pt/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">PT</a> | <a href="https://java.hotexamples.com/it/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">IT</a> | <a href="https://java.hotexamples.com/jp/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">JP</a> | <a href="https://java.hotexamples.com/zh/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">ZH</a> | <a href="https://java.hotexamples.com/ko/examples/javax.xml.stream/XMLStreamReader/getText/java-xmlstreamreader-gettext-method-examples.html">KO</a> </div> </div> <div class="row"> <div class="col-md-10 col-md-offset-1"> </div> <div class="col-md-1"> <!--LiveInternet counter--> <script type="text/javascript"><!-- document.write("<a href='//www.liveinternet.ru/click' " + "target=_blank><img src='//counter.yadro.ru/hit?t44.6;r" + escape(document.referrer) + ((typeof (screen) == "undefined") ? "" : ";s" + screen.width + "*" + screen.height + "*" + (screen.colorDepth ? screen.colorDepth : screen.pixelDepth)) + ";u" + escape(document.URL) + ";" + Math.random() + "' alt='' title='LiveInternet' " + "border='0' width='31' height='31'><\/a>"); //--></script><!--/LiveInternet--> </div> </div> </div> </footer> <script src="//ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="/assets/30dd86a6f06b64184847037c52c63e07aa3c9a26.js"></script> <script>jQuery(function ($) { jQuery('#search-form').yiiActiveForm([{"id":"searchform-lang","name":"lang","container":".field-searchform-lang","input":"#searchform-lang","enableAjaxValidation":true},{"id":"searchform-search","name":"search","container":".field-searchform-search","input":"#searchform-search","enableAjaxValidation":true,"validate":function (attribute, value, messages, deferred, $form) {yii.validation.required(value, messages, {"message":"Search cannot be blank."});}}], []); });</script></body> </html>