@@ -147,6 +147,17 @@ private void internalReadElement(String namespacePrefix, String localName,
147147 */
148148 public void read () throws ServiceXmlDeserializationException ,
149149 XMLStreamException {
150+ read (false );
151+ }
152+
153+ /**
154+ * Reads the specified node type.
155+ *
156+ * @throws ServiceXmlDeserializationException the service xml deserialization exception
157+ * @throws javax.xml.stream.XMLStreamException the xML stream exception
158+ */
159+ private void read (boolean keepWhiteSpace ) throws ServiceXmlDeserializationException ,
160+ XMLStreamException {
150161 // The caller to EwsXmlReader.Read expects
151162 // that there's another node to
152163 // read. Throw an exception if not true.
@@ -158,9 +169,10 @@ public void read() throws ServiceXmlDeserializationException,
158169 XMLEvent event = xmlReader .nextEvent ();
159170 if (event .getEventType () == XMLStreamConstants .CHARACTERS ) {
160171 Characters characters = (Characters ) event ;
161- if (characters .isIgnorableWhiteSpace ()
162- || characters .isWhiteSpace ()) {
163- continue ;
172+ if (!keepWhiteSpace )
173+ if (characters .isIgnorableWhiteSpace ()
174+ || characters .isWhiteSpace ()) {
175+ continue ;
164176 }
165177 }
166178 this .prevEvent = this .presentEvent ;
@@ -389,18 +401,31 @@ public <T> T readElementValue(Class<T> cls) throws Exception {
389401 */
390402 public String readValue () throws XMLStreamException ,
391403 ServiceXmlDeserializationException {
404+ return readValue (false );
405+ }
406+ /**
407+ * Reads the value. Should return content element or text node as string
408+ * Present event must be START ELEMENT. After executing this function
409+ * Present event will be set on END ELEMENT
410+ *
411+ * @return String
412+ * @throws javax.xml.stream.XMLStreamException the xML stream exception
413+ * @throws ServiceXmlDeserializationException the service xml deserialization exception
414+ */
415+ public String readValue (boolean keepWhiteSpace ) throws XMLStreamException ,
416+ ServiceXmlDeserializationException {
392417 String errMsg = String .format ("Could not read value from %s." ,
393418 XmlNodeType .getString (this .presentEvent .getEventType ()));
394419 if (this .presentEvent .isStartElement ()) {
395420 // Go to next event and check for Characters event
396- this .read ();
421+ this .read (keepWhiteSpace );
397422 if (this .presentEvent .isCharacters ()) {
398423 StringBuffer elementValue = new StringBuffer ();
399424 do {
400425 if (this .getNodeType ().nodeType == XmlNodeType .CHARACTERS ) {
401426 Characters characters = (Characters ) this .presentEvent ;
402- if (!characters .isIgnorableWhiteSpace ()
403- && !characters .isWhiteSpace ()) {
427+ if (keepWhiteSpace || ( !characters .isIgnorableWhiteSpace ()
428+ && !characters .isWhiteSpace ())) {
404429 if (characters .getData ().length () != 0 ) {
405430 elementValue .append (characters .getData ());
406431 }
@@ -427,11 +452,11 @@ public String readValue() throws XMLStreamException,
427452 StringBuffer data = new StringBuffer (this .presentEvent
428453 .asCharacters ().getData ());
429454 do {
430- this .read ();
455+ this .read (keepWhiteSpace );
431456 if (this .getNodeType ().nodeType == XmlNodeType .CHARACTERS ) {
432457 Characters characters = (Characters ) this .presentEvent ;
433- if (!characters .isIgnorableWhiteSpace ()
434- && !characters .isWhiteSpace ()) {
458+ if (keepWhiteSpace || ( !characters .isIgnorableWhiteSpace ()
459+ && !characters .isWhiteSpace ())) {
435460 if (characters .getData ().length () != 0 ) {
436461 data .append (characters .getData ());
437462 }
0 commit comments