EldoS | Feel safer!

Software components for data protection, secure storage and transfer

XML Text

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#18400
Posted: 12/07/2011 10:51:52
by Leonardo Herrera (Standard support level)
Joined: 02/14/2011
Posts: 66

Hello,

Using ElXMLDOMDocument and related classes, is it possible to obtain it as a String with all empty text elements removed? For example,

Code
<a>
    <b>some data</b>
    <c>Another data  <c>
</a>


should resolve to

Code
<a><b>some data</b><c>Another data  </c></a>



Thanks in advance,
Leo
#18404
Posted: 12/07/2011 11:27:25
by Dmytro Bogatskyy (EldoS Corp.)

There is no such function, but it could be easily done with a similar code:
Code
procedure RemoveEmptyText(Node : TElXMLDOMNode);
var
  TmpNode, NextNode : TElXMLDOMNode;
  TextNode : TElXMLDOMText;
begin
  TmpNode := Node.FirstChild;
  while Assigned(TmpNode) do
  begin
     NextNode := TmpNode.NextSibling;
     if TmpNode.NodeType = ntText then
     begin
       TextNode := TElXMLDOMText(TmpNode);
       if Trim(TextNode.Data) = '' then
         Node.RemoveChild(TmpNode)
       else
         TextNode.NodeValue := StringReplace(Trim(TextNode.NodeValue), ' '#$0A, #$0A);
     end
     else if TmpNode.NodeType = ntElement then
       RemoveEmptyText(TmpNode);

     TmpNode := NextNode;
  end;
end;

RemoveEmptyText(XMLDocument.DocumentElement);
Output := XMLDocument.DocumentElement.OuterXML;
#18405
Posted: 12/07/2011 11:45:19
by Leonardo Herrera (Standard support level)
Joined: 02/14/2011
Posts: 66

Thank you very much, Dmytro!

Reply

Statistics

Topic viewed 636 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!