@@ -164,7 +164,7 @@ public void FinishWrite()
164164 }
165165 _xmlWriter . WriteEndElement ( ) ; // row
166166 }
167-
167+
168168 _xmlWriter . WriteEndElement ( ) ; // rows
169169 _xmlWriter . WriteEndElement ( ) ; // data
170170 _xmlWriter . Close ( ) ;
@@ -174,7 +174,7 @@ public void FinishWrite()
174174 PostProcess ( ) ;
175175 }
176176
177- private void PostProcess ( )
177+ private void PostProcess ( )
178178 {
179179 // Acumatica requires all occurrences of tabs inside XML content to be encoded
180180 // as 	 instead of the tab character. This is a bit of a pain, but we have to do it.
@@ -188,6 +188,7 @@ private void PostProcess()
188188 using ( var writer = new System . IO . StreamWriter ( fileNameTarget , false , Encoding . UTF8 ) )
189189 {
190190 string ? line ;
191+ bool inCData = false ;
191192 while ( ( line = reader . ReadLine ( ) ) != null )
192193 {
193194 // Replace all tabs AFTER the first ones on each line (indentations) with 	
@@ -196,7 +197,37 @@ private void PostProcess()
196197 {
197198 firstNonTab ++ ;
198199 }
199- line = line . Substring ( 0 , firstNonTab ) + line . Substring ( firstNonTab ) . Replace ( "\t " , "	" ) ;
200+ // Check for CDATA sections
201+ if ( line . Contains ( "<![CDATA[" ) )
202+ {
203+ // Inside CDATA sections, tabs must NOT be replaced
204+ // Two cases: CDATA ends on the same line, or on a different line
205+ int cdataEnd = line . IndexOf ( "]]>" ) ;
206+ if ( cdataEnd > 0 )
207+ {
208+ // CDATA ends on the same line
209+ line = line . Substring ( 0 , cdataEnd + 3 ) + line . Substring ( cdataEnd + 3 ) . Replace ( "\t " , "	" ) ;
210+ }
211+ else
212+ {
213+ inCData = true ;
214+ }
215+ }
216+ else if ( inCData )
217+ {
218+ // We are inside a CDATA section, so we need to check for the end
219+ int cdataEnd = line . IndexOf ( "]]>" ) ;
220+ if ( cdataEnd > 0 )
221+ {
222+ // CDATA ends on this line
223+ inCData = false ;
224+ line = line . Substring ( 0 , cdataEnd + 3 ) + line . Substring ( cdataEnd + 3 ) . Replace ( "\t " , "	" ) ;
225+ }
226+ }
227+ else
228+ {
229+ line = line . Substring ( 0 , firstNonTab ) + line . Substring ( firstNonTab ) . Replace ( "\t " , "	" ) ;
230+ }
200231 writer . WriteLine ( line ) ;
201232 }
202233 }
0 commit comments