Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-11

TDOMParseOptions, TDOMParser, TXMLDocument, ... how to set TDOMParser Options?

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Joyner ᏩᏯ

TDOMParseOptions, TDOMParser, TXMLDocument, ... how to set TDOMParser Options?

I am trying to the use the xmlread and xmlwrite units.

I would like to set the DOM Parser options, I can see in 'fpcsrc/2.2.4/packages/fcl-xml/src' they are defined in the class by another class called TDOMParserOptions, but they are read only in the TDOMParser Class?

I tried Googling for example usages for the units, but came up empty for trying to setup options.

Sample code that won't work do to the read only option for the options:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog.Execute then begin
     domOptions := TDOMParseOptions.Create;
     domOptions.ExpandEntities:=true;
     domParser := TDOMParser.Create;
     domParser.Options := domOptions;
     xdoc := TXMLDocument.create;
     domParser.ParseURI(OpenDialog.Filename,xdoc);
  end;
end;

Reply by email

Sergei Gorelkin
to Michael Joyner ᏩᏯ

Michael Joyner ?? ?????:

Show quoted text 9 lines
TDOMParseOptions, TDOMParser, TXMLDocument, ... how to set TDOMParser Options? I am trying to the use the xmlread and xmlwrite units. I would like to set the DOM Parser options, I can see in 'fpcsrc/2.2.4/packages/fcl-xml/src' they are defined in the class by another class called TDOMParserOptions, but they are read only in the TDOMParser Class?

You don't need to create an instance of TDOMParseOptions. Every TDOMParser already has one available. Just create a TDOMParser and set its options like this:

domParser := TDOMParser.Create;
domParser.Options.ExpandEntities := True;

See e.g. the "Validating a document" example in http://wiki.freepascal.org/XML_Tutorial

Show quoted text 13 lines
Sample code that won't work do to the read only option for the options: procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog.Execute then begin domOptions := TDOMParseOptions.Create; domOptions.ExpandEntities:=true; domParser := TDOMParser.Create; domParser.Options := domOptions; xdoc := TXMLDocument.create; domParser.ParseURI(OpenDialog.Filename,xdoc); end; end;

Note that you don't have to create a TXMLDocument before parsing, because parser always creates one. Also, using filename directly as an URI won't work on e.g. Windows; use FilenameToURI function from URIParser unit to convert it in a crossplatform way.

Regards,
Sergei

Reply by email

Michael Joyner ᏩᏯ
to Sergei Gorelkin
Sergei Gorelkin wrote 11 lines
Michael Joyner ?? ?????: > TDOMParseOptions, TDOMParser, TXMLDocument, ... how to set TDOMParser > Options? has one available. Just create a TDOMParser and set its options like this: domParser := TDOMParser.Create; domParser.Options.ExpandEntities := True; See e.g. the "Validating a document" example in http://wiki.freepascal.org/XML_Tutorial

Sample code that does now work:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog.Execute then begin
     domParser := TDOMParser.Create;
     domParser.Options.ExpandEntities:=True;
     domParser.Options.PreserveWhitespace:=False;
     domParser.Options.ResolveExternals:=True;
     domParser.Options.Namespaces:=True;
     domParser.Options.CDSectionsAsText:=False;
     domParser.ParseURI(FileNameToURI(OpenDialog.Filename),xdoc);
  end;
end;

Is there any way to have the domParser process <import> tags ?

Reply by email