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?

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

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

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to