Link to home
Start Free TrialLog in
Avatar of Eddie Shipman
Eddie ShipmanFlag for United States of America

asked on

Not include ProcessingInstruction, please

I am using the Delphi code below to save my IXMLDOMDocument2 to a file, I am using this because it makes it human readable.

However, I do not require the ProcessingInstruction. I am not creating one in the document so I'm thinking this code is somehow putting it in there. Any thoughts??

procedure SaveXML(AXML: IXMLDOMDocument2; APath: String);
var
  wrt: MXXMLWriter40;
  sax: SAXXMLReader40;
  memoutput: TMemoryStream;
begin
  wrt := CoMXXMLWriter40.Create;
  sax := CoSAXXMLReader40.Create;
  sax.contentHandler := (wrt as IVBSAXContentHandler) ;
  sax.dtdHandler := (wrt as IVBSAXDTDHandler);
  sax.errorHandler := (wrt as IVBSAXErrorHandler);
  sax.putProperty('http://xml.org/sax/properties/declaration-handler', wrt);
  sax.putProperty('http://xml.org/sax/properties/lexical-handler', wrt);
  try
    wrt.indent := True;
    wrt.disableOutputEscaping := True;
    wrt.omitXMLDeclaration := False;
    memoutput := TMemoryStream.Create;
    try
      wrt.output := TStreamAdapter.Create(memoutput) as IStream;
      sax.parse(AXML);
      memoutput.Position := 0;
      memoutput.SaveToFile(APath);
    finally
      memoutput.Free;
    end;
  finally
    wrt := nil;
    sax := nil;
  end;
end;
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

ASKER

BTW, using the IXMLDOMDocument save method DOES NOT place the PI in the document but it is not
indented.
Yes, I have tried the preserveWhiteSpace property, with no effect.
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I thought Itried that, too, we'll see..