IXMLDocument.SaveToFile () uses a tab character to indent instead of spaces

I have an XML file that is initially formatted using space indentation (2 spaces for each nested element).

When I load and save this file using IXMLDocument, the space indents change to tabs (code # 9).

Here is the code:

var FileName: String; Document: IXMLDocument; ... Document := XMLDoc.LoadXMLDocument(FileName); Document.SaveToFile(FileName); 

I tried using the NodeIndentStr property - there is no result:

  Document := XMLDoc.LoadXMLDocument(FileName); Document.NodeIndentStr := ' '; Document.SaveToFile(FileName); 

Used FormatXMLData too - no result:

  Document := XMLDoc.LoadXMLDocument(FileName); Document.XML.Text := XMLDoc.FormatXMLData(Document.XML.Text); Document.Active := True; Document.SaveToFile(FileName); 

How to save space values ​​instead of tabs?

+7
source share
2 answers

IXMLDocument has an option where the parser may be asked to keep spaces.

Use it as follows:

 Document.ParseOptions := Document.ParseOptions+[poValidateOnParse]+[poPreserveWhiteSpace]; 

Disclaimer: I have not tried.

+11
source

I'm not sure what else, but Document.ParseOptions + [poValidateOnParse, poPreserveWhiteSpace]; was unavailable to me.

Something like this worked:

 var xmlDoc: IXMLDOMDocument2; xmlDoc := CreateOleObject('Microsoft.XMLDOM') as IXMLDOMDocument2; xmlDoc.validateOnParse := True; xmlDoc.preserveWhiteSpace := True; 
0
source

All Articles