@@ -159,6 +159,19 @@ private void internalReadElement(String namespacePrefix, String localName,
159159 */
160160 public void read () throws ServiceXmlDeserializationException ,
161161 XMLStreamException {
162+ read (false );
163+ }
164+
165+ /**
166+ * Reads the specified node type.
167+ *
168+ * @param keepWhiteSpace Do not remove whitespace characters if true
169+ *
170+ * @throws ServiceXmlDeserializationException the service xml deserialization exception
171+ * @throws javax.xml.stream.XMLStreamException the xML stream exception
172+ */
173+ private void read (boolean keepWhiteSpace ) throws ServiceXmlDeserializationException ,
174+ XMLStreamException {
162175 // The caller to EwsXmlReader.Read expects
163176 // that there's another node to
164177 // read. Throw an exception if not true.
@@ -170,9 +183,10 @@ public void read() throws ServiceXmlDeserializationException,
170183 XMLEvent event = xmlReader .nextEvent ();
171184 if (event .getEventType () == XMLStreamConstants .CHARACTERS ) {
172185 Characters characters = (Characters ) event ;
173- if (characters .isIgnorableWhiteSpace ()
174- || characters .isWhiteSpace ()) {
175- continue ;
186+ if (!keepWhiteSpace )
187+ if (characters .isIgnorableWhiteSpace ()
188+ || characters .isWhiteSpace ()) {
189+ continue ;
176190 }
177191 }
178192 this .prevEvent = this .presentEvent ;
@@ -401,18 +415,32 @@ public <T> T readElementValue(Class<T> cls) throws Exception {
401415 */
402416 public String readValue () throws XMLStreamException ,
403417 ServiceXmlDeserializationException {
418+ return readValue (false );
419+ }
420+ /**
421+ * Reads the value. Should return content element or text node as string
422+ * Present event must be START ELEMENT. After executing this function
423+ * Present event will be set on END ELEMENT
424+ *
425+ * @param keepWhiteSpace Do not remove whitespace characters if true
426+ * @return String
427+ * @throws javax.xml.stream.XMLStreamException the xML stream exception
428+ * @throws ServiceXmlDeserializationException the service xml deserialization exception
429+ */
430+ public String readValue (boolean keepWhiteSpace ) throws XMLStreamException ,
431+ ServiceXmlDeserializationException {
404432 String errMsg = String .format ("Could not read value from %s." ,
405433 XmlNodeType .getString (this .presentEvent .getEventType ()));
406434 if (this .presentEvent .isStartElement ()) {
407435 // Go to next event and check for Characters event
408- this .read ();
436+ this .read (keepWhiteSpace );
409437 if (this .presentEvent .isCharacters ()) {
410438 StringBuffer elementValue = new StringBuffer ();
411439 do {
412440 if (this .getNodeType ().nodeType == XmlNodeType .CHARACTERS ) {
413441 Characters characters = (Characters ) this .presentEvent ;
414- if (!characters .isIgnorableWhiteSpace ()
415- && !characters .isWhiteSpace ()) {
442+ if (keepWhiteSpace || ( !characters .isIgnorableWhiteSpace ()
443+ && !characters .isWhiteSpace ())) {
416444 if (characters .getData ().length () != 0 ) {
417445 elementValue .append (characters .getData ());
418446 }
@@ -439,11 +467,11 @@ public String readValue() throws XMLStreamException,
439467 StringBuffer data = new StringBuffer (this .presentEvent
440468 .asCharacters ().getData ());
441469 do {
442- this .read ();
470+ this .read (keepWhiteSpace );
443471 if (this .getNodeType ().nodeType == XmlNodeType .CHARACTERS ) {
444472 Characters characters = (Characters ) this .presentEvent ;
445- if (!characters .isIgnorableWhiteSpace ()
446- && !characters .isWhiteSpace ()) {
473+ if (keepWhiteSpace || ( !characters .isIgnorableWhiteSpace ()
474+ && !characters .isWhiteSpace ())) {
447475 if (characters .getData ().length () != 0 ) {
448476 data .append (characters .getData ());
449477 }
0 commit comments