Sign in Join

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

Mailing lists / lazarus / 2015-10

TSynMemo + TSynXMLSyn: How format a XML after load it?

9 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Marcos Douglas
to Mattias Gaertner
Mattias Gaertner wrote 9 lines
On Wed, 28 Oct 2015 01:17:23 -0200 Marcos Douglas wrote: > Hi, > > I'm using TSynMemo and TSynXMLSyn. > How format a XML after load it? Please define "format".

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

Reply by email

Mattias Gaertner
to Marcos Douglas
Show quoted text 43 lines
On Wed, Oct 28, 2015 at 6:48 AM, Mattias Gaertner wrote: > On Wed, 28 Oct 2015 01:17:23 -0200 > Marcos Douglas wrote: > >> Hi, >> >> I'm using TSynMemo and TSynXMLSyn. >> How format a XML after load it? > > Please define "format". 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?

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

Reply by email

Marcos Douglas
to Mattias Gaertner
Mattias Gaertner wrote 10 lines
On Wed, 28 Oct 2015 09:43:23 -0200 Marcos Douglas wrote: > [...] > ...automatically, by set a property or use a method. > Is it possible? 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).

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.

Show quoted text 7 lines
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.

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

Reply by email

Mattias Gaertner
to Marcos Douglas
Show quoted text 6 lines
[...] You suggest use fpc xml writer to: 1- load the original XML without spaces 2- save the XML after with automatically spaces Like that?

Yes.

I don't know the fpc xml write yet, so I'm asking how use it.

ReadXMLFile
WriteXMLFile

[...]

Mattias

Reply by email

Anthony Walter
to Marcos Douglas: 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>

Reply by email

Anthony Walter
to Marcos Douglas

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>

Reply by email