Use of TROOpenXMLDocument

Hi,

I need to read and write some general XML files and was thinking of using your TROOpenXMLDocument instead of the built-in TXMLDocument. Would you advise this or is there no real benefit over using the built-in functionality which leverages the MSXML parser?

One thing I noticed when using your classes was that, when writing out to a file, there are no line breaks between elements which can make the file hard to read in a standard text editor - is there any way of modifying this behaviour?

Similarly, when reading a file which does have such line breaks, these appear in the structure as additional nodes with names like ‘#text’. Is there any way of stripping these out automatically?

I appreciate that your implementation is primarily for the internal use of the RO framework when serialising information across the wire and I may be on totally the wrong track thinking of using it for my own XML files but I’d appreciate your opinion on the matter.

we are using OpenXML implementation for linux-based system, i.e. where MSXML implementation isn’t supported.
OpenXML has some limitations and you have caught some of them.

You can remove #text with something like:

procedure TDAWhereBuilder.RemoveEmptyNodes(const ANode: IXMLNode);
var
  i: integer;
  lNode: IXMLNode;
begin
  i:=0;
  while i < ANode.ChildrenCount do begin
    lNode := ANode.Children[i];
    if (lNode.Name = '#text') and (lNode.LocalName = '') and (lNode.Value = ' ')  then
      ANode.Delete(i)
    else begin
      RemoveEmptyNodes(lNode);
      inc(i);
    end;
  end;
end;