Sign in Join

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

Mailing lists / fpc-pascal / 2019-04

XML - Indent, text content, special char

13 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Gabor Boros

Hi All,

I have an existing XML file. After load(, modify) and save this file some mandatory formatting things lost from it. I need same indent as before, same text contents and not replace every special chars. With the below code I got the attached OUTPUT.xml from the attached INPUT.xml. Any idea how to solve this problem? (I use fixes_3_2.)

X:=TXMLDocument.Create;
ReadXMLFile(X,'INPUT.xml');
WriteXMLFile(X,'OUTPUT.xml');

Gabor

Michael Van Canneyt
to Gabor Boros
Gabor Boros wrote 11 lines
Hi All, I have an existing XML file. After load(, modify) and save this file some mandatory formatting things lost from it. I need same indent as before, same text contents and not replace every special chars. With the below code I got the attached OUTPUT.xml from the attached INPUT.xml. Any idea how to solve this problem? (I use fixes_3_2.) X:=TXMLDocument.Create; ReadXMLFile(X,'INPUT.xml'); WriteXMLFile(X,'OUTPUT.xml');

As far as I know you can't. I recently changed some things in xmlwriter so you can influence the formatting to some degree, but no attempt is made to respect the formatting of a previously read file. I believe the formatting info is discarded on read (I would need to veify) so this would require lots of rewriting.

Michael.

Gabor Boros
to Michael Van Canneyt

2019. 04. 27. 13:57 keltezéssel, Michael Van Canneyt írta:

Show quoted text 6 lines
As far as I know you can't. I recently changed some things in xmlwriter so you can influence the formatting to some degree, but no attempt is made to respect the formatting of a previously read file. I believe the formatting info is discarded on read (I would need to veify) so this would require lots of rewriting.

The "indent" and "text content" problems solved on the reader side by ReadXMLFilePreserveWhitespace:

http://wiki.freepascal.org/XML_Tutorial#Whitespace_characters

Gabor

Michael Van Canneyt
to Gabor Boros
Gabor Boros wrote 12 lines
2019. 04. 27. 13:57 keltezéssel, Michael Van Canneyt írta: > As far as I know you can't. I recently changed some things in xmlwriter > so you can > influence the formatting to some degree, but no attempt is made to respect > the formatting of a previously read file. I believe the formatting info is > discarded on read (I would need to veify) so this would require lots of > rewriting. The "indent" and "text content" problems solved on the reader side by ReadXMLFilePreserveWhitespace: http://wiki.freepascal.org/XML_Tutorial#Whitespace_characters

Nice. Again something learned.

In that case, disabling indent (set size=0) and CRLF (set lineending to 0-empty string) in the newly exposed XMLWriter will probably do the trick.

Michael.

Michael Van Canneyt
to Gabor Boros
Gabor Boros wrote 5 lines
2019. 04. 28. 9:35 keltezéssel, Michael Van Canneyt írta: > the newly exposed XMLWriter Will be merged/backported into fixes_3_2?

I just merged it.

Michael.

Gabor Boros
to Gabor Boros: 2019. 04. 27. 13:57 keltezéssel, Michael Van Canneyt írta: The "indent" and "text…

2019. 04. 28. 9:25 keltezéssel, Gabor Boros írta:

The "indent" and "text content" problems solved on the reader side by ReadXMLFilePreserveWhitespace:

With a sample application but not with the real life application. :-( (My real application just find node for every second FindNode call.)

With the attached example and test xml file I got the next result:

*a*
**

Is this not a bug? Lost of formatting is not disturb me but text between

and < is the data/text content of a node.

Gabor

Unknown author
to Gabor Boros: 2019. 04. 28. 9:25 keltezéssel, Gabor Boros írta: With a sample application but not…
Gabor Boros wrote
Is this not a bug? Lost of formatting is not disturb me but text between > and < is the data/text content of a node.

are you saying that you are trying to use fixed-width fields that are space-padded in XML files???

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list unless* *a signed and pre-paid contract is in effect with us.*
Bernd Oppolzer
to Unknown author

Am 30.04.2019 um 02:45 schrieb

Show quoted text 8 lines
On 4/29/19 1:27 PM, Gabor Boros wrote: > Is this not a bug? Lost of formatting is not disturb me but text > between > and < is the data/text content of a node. are you saying that you are trying to use fixed-width fields that are space-padded in XML files???

There is nothing wrong with that,
in fact I am aware of a typesetting system which uses XML as input, and if you enclose your input text between certain tags (<pre> or <sourcecode>)
you expect that the blanks between those tags are preserved.

The W3C standards, IMO, don't tell anything about what a certain parser etc. should do to XML content (IMO, not much), there are not many restrictions
(<, of course, should be &lt;) ... attributes are different, of course.

Kind regards

Bernd

Unknown author
to Bernd Oppolzer
Bernd Oppolzer wrote 9 lines
Am 30.04.2019 um 02:45 schrieb > On 4/29/19 1:27 PM, Gabor Boros wrote: >> Is this not a bug? Lost of formatting is not disturb me but text between > >> and < is the data/text content of a node. > > are you saying that you are trying to use fixed-width fields that are > space-padded in XML files??? There is nothing wrong with that,

agreed...

in fact I am aware of a typesetting system which uses XML as input, and if you enclose your input text between certain tags (<pre> or <sourcecode>) you expect that the blanks between those tags are preserved.

true but the given examples do not show that...

[code]
<?xml version="1.0" encoding="utf-8"?>
<doc>
<text1> a</text1>
<text2> </text2>
</doc>
[/code]

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list unless* *a signed and pre-paid contract is in effect with us.*
Gabor Boros
to Unknown author: are you saying that you are trying to use fixed-width fields that are space-padded in XML…

2019. 04. 30. 2:45 keltezéssel, írta:

are you saying that you are trying to use fixed-width fields that are space-padded in XML files???

No. The XML files are exists already. The task is... Load the contents/file to a TObject descendant, modify the data in the object(s) then build up XMLs from it a save back to file(s). Without lost any "TDOMNode.TextContent".

Gabor