Hi,
I'm using TSynMemo and TSynXMLSyn.
How format a XML after load it?
Thanks,
Marcos Douglas

Mailing lists / lazarus / 2015-10
9 messages · 3 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
I'm using TSynMemo and TSynXMLSyn.
How format a XML after load it?
Thanks,
Marcos Douglas
Hi, I'm using TSynMemo and TSynXMLSyn. How format a XML after load it?
Please define "format".
Mattias
Ok, sorry.
I meant format this:
<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" mlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body> <ConsultaAndamentos> <Result> <Andamento> <Pasta>int</Pasta> <Processo>string</Processo> </Andamento>
</Result></ConsultaAndamentos></soap12:Body>/soap12:Envelope>
in this:
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body>
<ConsultaAndamentos>
<Result>
<Andamento>
<Pasta>int</Pasta>
<Processo>string</Processo>
</Andamento>
</Result>
</ConsultaAndamentos>
</soap12:Body>
</soap12:Envelope>
...automatically, by set a property or use a method. Is it possible?
Thanks,
Marcos Douglas
You have to define what to do with text elements containing only space (e.g. <element> </element>). By default it should keep the spaces (Note: spaces include tabs and line breaks).
Further complications: CDATA.
The current fpc xml writer creates the indentation, but messes up text element.
The laz2_xml writer has a flag to keep the indentation and preserving text elements. This could be extended with a further flag to indent elements gaps while preserving text elements.
Or you can simply write a function that works for your xml files.
Mattias
The original XML comes from a WebService and not contains spaces.
Part of my program is exhibit this XML to user to him check erros, send for other person, log, etc.
Would be better show these XML with indentation.
You suggest use fpc xml writer to:
1- load the original XML without spaces
2- save the XML after with automatically spaces
Like that?
I don't know the fpc xml write yet, so I'm asking how use it.
Or you can simply write a function that works for your xml files.
Not simple to do that. The program don't know nothing about the XML before call them, because there is many WebServices. The program is just a tool for "debbuger" informations.
Marcos Douglas
Yes.
I don't know the fpc xml write yet, so I'm asking how use it.
ReadXMLFile
WriteXMLFile
[...]
Mattias
On Wed, Oct 28, 2015 at 6:48 AM, Mattias Gaertner Ok, sorry. I meant format this: <?xml…
uses
Codebot.Text.Xml;
function PrettyXml(const Xml: string): string;
var
D: IDocument;
begin
D := DocumentCreate;
D.Xml := Xml;
D.Beautify;
Result := D.Xml;
end;{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text := PrettyXml(Memo1.Text);
end;Result:
<?xml version="1.0" encoding="UTF-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" mlns:xsd=" http://www.w3.org/2001/XMLSchema">
<soap12:Body>
<ConsultaAndamentos>
<Result>
<Andamento>
<Pasta>int</Pasta>
<Processo>string</Processo>
</Andamento>
</Result>
</ConsultaAndamentos>
</soap12:Body>
</soap12:Envelope>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151028/aae47d39/attachment.html>
Thank you!
Marcos, here are a few notes when working with Codebot.Text.Xml:
* You can use IDocument.Load/Save to load and save Xml to and from files.
* If the Xml text is in an invalid state, the IDocument will be empty.
* Attempts to read an empty IDocument Text or Xml property return an empty Xml doctype.
* You can check if IDocument contains valid Xml by seeing if the root node exists. ie: Document.Root nil
* Alternately you can validate Xml using the XmlValidate function...
function XmlValidate(const Xml: string): Boolean;-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151028/497e7e6a/attachment.html>