@@ -16,15 +16,17 @@ namespace Peachpie.Library.XmlDom
16
16
[ PhpType ( PhpTypeAttribute . InheritName ) , PhpExtension ( "xmlwriter" ) ]
17
17
public class XMLWriter : IDisposable
18
18
{
19
+
19
20
#region Constants
20
21
21
22
private protected const string DefaultXmlVersion = "1.0" ;
22
23
23
24
#endregion
24
25
25
26
#region Fields and properties
27
+ XmlTextWriter _writer ;
26
28
27
- System . Xml . XmlWriter _writer ;
29
+ //wjw - System.Xml.XmlWriter _writer;
28
30
MemoryStream _memoryStream ;
29
31
PhpStream _uriPhpStream ;
30
32
@@ -212,7 +214,7 @@ public bool endDtd()
212
214
_state . Pop ( ) ;
213
215
214
216
// Closes dtd section.
215
- string end = _writer . Settings . Indent ? _writer . Settings . NewLineChars : "" ;
217
+ string end = _writer . Formatting == Formatting . Indented ? DefaultSettings . NewLineChars : "" ; // string end = _writer. Settings.Indent ? _writer.Settings.NewLineChars : "";
216
218
end += _dtdStart ? ">" : "]>" ;
217
219
_dtdStart = false ;
218
220
@@ -292,7 +294,9 @@ public bool openMemory(Context ctx)
292
294
{
293
295
Clear ( ) ;
294
296
_memoryStream = new MemoryStream ( ) ;
295
- _writer = System . Xml . XmlWriter . Create ( _memoryStream , DefaultSettings ) ;
297
+ _writer = new XmlTextWriter ( _memoryStream , DefaultSettings . Encoding ) ; //_writer = System.Xml.XmlWriter.Create(_memoryStream, DefaultSettings);
298
+ _writer . Formatting = DefaultSettings . Indent ? Formatting . Indented : Formatting . None ;
299
+
296
300
ctx . RegisterDisposable ( this ) ;
297
301
return true ;
298
302
}
@@ -309,7 +313,7 @@ public bool openUri(Context ctx, string uri)
309
313
310
314
try
311
315
{
312
- _writer = System . Xml . XmlWriter . Create ( _uriPhpStream . RawStream , DefaultSettings ) ;
316
+ _writer = new XmlTextWriter ( _uriPhpStream . RawStream , DefaultSettings . Encoding ) ; //_writer = System.Xml.XmlWriter.Create(_uriPhpStream.RawStream, DefaultSettings);
313
317
ctx . RegisterDisposable ( this ) ;
314
318
return true ;
315
319
}
@@ -340,13 +344,13 @@ public bool setIndentString(string indentString)
340
344
return false ;
341
345
342
346
// The settings is read-only, but we can create a new xmlwriter if the current xmlwriter haven't written anything yet.
343
- var settings = _writer . Settings . Clone ( ) ;
347
+ var settings = DefaultSettings . Clone ( ) ; // var settings = _writer.Settings.Clone();
344
348
settings . IndentChars = indentString ;
345
349
346
350
if ( _uriPhpStream == null )
347
- _writer = XmlWriter . Create ( _memoryStream , settings ) ;
351
+ _writer = new XmlTextWriter ( _memoryStream , settings . Encoding ) ; //_writer = XmlWriter.Create(_memoryStream, settings);
348
352
else
349
- _writer = XmlWriter . Create ( _uriPhpStream . RawStream , settings ) ;
353
+ _writer = new XmlTextWriter ( _uriPhpStream . RawStream , settings . Encoding ) ; //_writer = XmlWriter.Create(_uriPhpStream.RawStream, settings);
350
354
351
355
return true ;
352
356
}
@@ -357,13 +361,13 @@ public bool setIndent(bool indent)
357
361
return false ;
358
362
359
363
// The settings is read-only, but we can create a new xmlwriter if the current xmlwriter haven't written anything yet.
360
- var settings = _writer . Settings . Clone ( ) ;
364
+ var settings = DefaultSettings . Clone ( ) ; // var settings = _writer.Settings.Clone();
361
365
settings . Indent = indent ;
362
366
363
367
if ( _uriPhpStream == null )
364
- _writer = XmlWriter . Create ( _memoryStream , settings ) ;
368
+ _writer = new XmlTextWriter ( _memoryStream , settings . Encoding ) ; //_writer = XmlWriter.Create(_memoryStream, settings);
365
369
else
366
- _writer = XmlWriter . Create ( _uriPhpStream . RawStream , settings ) ;
370
+ _writer = new XmlTextWriter ( _uriPhpStream . RawStream , settings . Encoding ) ; //_writer = XmlWriter.Create(_uriPhpStream.RawStream, settings);
367
371
368
372
return true ;
369
373
}
@@ -422,16 +426,16 @@ public bool startDocument(string version = DefaultXmlVersion, string encoding =
422
426
if ( string . IsNullOrEmpty ( standalone ) )
423
427
{
424
428
bool res = CheckedCall ( ( ) => _writer . WriteStartDocument ( ) ) ;
425
- if ( ! _writer . Settings . Indent ) // Php writes a new line character after prolog.
426
- res &= CheckedCall ( ( ) => _writer . WriteRaw ( _writer . Settings . NewLineChars ) ) ;
429
+ if ( _writer . Formatting == Formatting . None ) // if ( !_writer.Settings.Indent) // Php writes a new line character after prolog.
430
+ res &= CheckedCall ( ( ) => _writer . WriteRaw ( DefaultSettings . NewLineChars ) ) ; //res &= CheckedCall(() => _writer.WriteRaw( _writer.Settings.NewLineChars));
427
431
428
432
return res ;
429
433
}
430
434
else
431
435
{
432
436
bool res = CheckedCall ( ( ) => _writer . WriteStartDocument ( standalone == "yes" ) ) ;
433
- if ( ! _writer . Settings . Indent ) // Php writes a new line character after prolog.
434
- res &= CheckedCall ( ( ) => _writer . WriteRaw ( _writer . Settings . NewLineChars ) ) ;
437
+ if ( _writer . Formatting == Formatting . None ) // if ( !_writer.Settings.Indent) // Php writes a new line character after prolog.
438
+ res &= CheckedCall ( ( ) => _writer . WriteRaw ( DefaultSettings . NewLineChars ) ) ; // res &= CheckedCall(() => _writer.WriteRaw( _writer.Settings.NewLineChars));
435
439
436
440
return res ;
437
441
}
@@ -476,7 +480,8 @@ public bool startDtdEntity(string name, bool isparam)
476
480
public bool startDtd ( string qualifiedName , string publicId = null , string systemId = null )
477
481
{
478
482
if ( _state . Count != 0 || // DTD can be only placed in default section and prolog.
479
- ( _writer . Settings . ConformanceLevel == ConformanceLevel . Document && _writer . WriteState != WriteState . Prolog && _writer . WriteState != WriteState . Start ) )
483
+ //(_writer.Settings.ConformanceLevel == ConformanceLevel.Document && _writer.WriteState != WriteState.Prolog && _writer.WriteState != WriteState.Start))
484
+ ( DefaultSettings . ConformanceLevel == ConformanceLevel . Document && _writer . WriteState != WriteState . Prolog && _writer . WriteState != WriteState . Start ) )
480
485
{
481
486
PhpException . Throw ( PhpError . Warning , Resources . XmlWritterDtdInProlog ) ;
482
487
return false ;
@@ -491,9 +496,11 @@ public bool startDtd(string qualifiedName, string publicId = null, string system
491
496
// Makes a doctype
492
497
string doctype = $ "<!DOCTYPE { qualifiedName } ";
493
498
if ( ! String . IsNullOrEmpty ( publicId ) )
494
- doctype += _writer . Settings . Indent ? $ "{ _writer . Settings . NewLineChars } PUBLIC \" { publicId } \" " : $ " PUBLIC \" { publicId } \" ";
499
+ //doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars}PUBLIC \"{publicId}\"" : $" PUBLIC \"{publicId}\"";
500
+ doctype += _writer . Formatting == Formatting . Indented ? $ "{ DefaultSettings . NewLineChars } PUBLIC \" { publicId } \" " : $ " PUBLIC \" { publicId } \" ";
495
501
if ( ! String . IsNullOrEmpty ( systemId ) )
496
- doctype += _writer . Settings . Indent ? $ "{ _writer . Settings . NewLineChars } SYSTEM \" { systemId } \" " : $ " SYSTEM \" { systemId } \" ";
502
+ //doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars}SYSTEM \"{systemId}\"" : $" SYSTEM \"{systemId}\"";
503
+ doctype += _writer . Formatting == Formatting . Indented ? $ "{ DefaultSettings . NewLineChars } SYSTEM \" { systemId } \" " : $ " SYSTEM \" { systemId } \" ";
497
504
498
505
CheckDtdStartHelper ( ) ;
499
506
_state . Push ( State . DTD ) ;
@@ -662,7 +669,8 @@ public bool writeDtdEntity(string name, string content, bool pe = false)
662
669
public bool writeDtd ( string name , string publicId = null , string systemId = null , string subset = null )
663
670
{
664
671
if ( _state . Count != 0 ||
665
- ( _writer . Settings . ConformanceLevel == ConformanceLevel . Document && _writer . WriteState != WriteState . Prolog && _writer . WriteState != WriteState . Start ) )
672
+ //(_writer.Settings.ConformanceLevel == ConformanceLevel.Document && _writer.WriteState != WriteState.Prolog && _writer.WriteState != WriteState.Start))
673
+ ( DefaultSettings . ConformanceLevel == ConformanceLevel . Document && _writer . WriteState != WriteState . Prolog && _writer . WriteState != WriteState . Start ) )
666
674
{
667
675
PhpException . Throw ( PhpError . Warning , Resources . XmlWritterDtdInProlog ) ;
668
676
return false ;
@@ -677,9 +685,11 @@ public bool writeDtd(string name, string publicId = null, string systemId = null
677
685
// Makes doctype
678
686
string doctype = $ "<!DOCTYPE { name } ";
679
687
if ( ! String . IsNullOrEmpty ( publicId ) )
680
- doctype += _writer . Settings . Indent ? $ "{ _writer . Settings . NewLineChars } PUBLIC \" { publicId } \" " : $ " PUBLIC \" { publicId } \" ";
688
+ //doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars}PUBLIC \"{publicId}\"" : $" PUBLIC \"{publicId}\"";
689
+ doctype += _writer . Formatting == Formatting . Indented ? $ "{ DefaultSettings . NewLineChars } PUBLIC \" { publicId } \" " : $ " PUBLIC \" { publicId } \" ";
681
690
if ( ! String . IsNullOrEmpty ( systemId ) )
682
- doctype += _writer . Settings . Indent ? $ "{ _writer . Settings . NewLineChars } \" { systemId } \" " : $ " \" { systemId } \" ";
691
+ //doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars} \"{systemId}\"" : $" \"{systemId}\"";
692
+ doctype += _writer . Formatting == Formatting . Indented ? $ "{ DefaultSettings . NewLineChars } \" { systemId } \" " : $ " \" { systemId } \" ";
683
693
if ( ! String . IsNullOrEmpty ( subset ) )
684
694
doctype += $ " [{ subset } ]";
685
695
doctype += ">" ;
@@ -740,9 +750,9 @@ private void CheckDtdStartHelper()
740
750
_dtdStart = false ;
741
751
}
742
752
743
- if ( _writer . Settings . Indent )
753
+ if ( _writer . Formatting == Formatting . Indented ) //if (_writer. Settings.Indent)
744
754
{
745
- _writer . WriteRaw ( _writer . Settings . NewLineChars ) ;
755
+ _writer . WriteRaw ( DefaultSettings . NewLineChars ) ; //_writer.WriteRaw( _writer.Settings.NewLineChars);
746
756
747
757
if ( _state . Count != 0 && _state . Peek ( ) == State . DTD )
748
758
_writer . WriteRaw ( " " ) ;
0 commit comments