Remove empty lines from XML file

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
DaLinx
Posts: 2
Joined: Tue Jan 28, 2025 12:38 pm
Location: Romania

Remove empty lines from XML file

Post by DaLinx »

Hi!
I created an XML file with VFP 9 *with command "Set alternate to name.xml".
How can I deleted an empty lines at the beginning file.
Also, at the end of file, appear the word "SUB".
Every time, I must to delete manual.
Please, excuse me for my english!
Thank you!
FFF
Posts: 1610
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: Remove empty lines from XML file

Post by FFF »

Hi and welcome to the forum!
First - you might use www.deepL.com to write any questions in your language and let it translate to english, it#s free and very good ;-)

Second:
That i got from KI

Code: Select all

USING System
USING System.IO
USING System.Linq

FUNCTION Start() AS VOID

	VAR inputFilePath := "input.xml" // Pfad zur Eingabedatei
	VAR outputFilePath := "output.xml" // Pfad zur Ausgabedatei

        // read file
	VAR lines := File.ReadAllLines(inputFilePath)

        // find empty lines
	VAR nonEmptyLines := lines.Where(line => !string.IsNullOrWhiteSpace(line)) // this the compiler doesn't like

        // write changed file
	File.WriteAllLines(outputFilePath, nonEmptyLines)

	Console.WriteLine("Empty Lines removed.")

RETURN
That does not compile, see the commented line, and i have no clue with Linq. Surely, one of the wise will jump in...

EDIT: I realize, that coming from Fox, this it no code that you'll like. But if so, don't you have code in Fox for this job? You might show here.
If not, the idea is as above: read the file into an array of lines, iterate through the array and copy any non empty (or "SUB") line into another array, write this array into a file.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
kevclark64
Posts: 131
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

Re: Remove empty lines from XML file

Post by kevclark64 »

I've never used SET ALTERNATE although I've used SET PRINTER TO and SET PRINT ON which is functionally pretty much the same thing. I don't know exactly what you're trying to do, but it sounds like using TEXT ... ENDTEXT (probably with TEXTMERGE) would give you finer control of the output. Using that you would create a variable in memory with your text and you can use STRTOFILE to save it.

BTW, this isn't a general purpose Visual FoxPro forum, it's more about X Sharp and using X Sharp coming from Visual Foxpro. For a very good and active Foxpro forum you can try https://www.foxite.com/
DaLinx
Posts: 2
Joined: Tue Jan 28, 2025 12:38 pm
Location: Romania

Re: Remove empty lines from XML file

Post by DaLinx »

I want to create the SAFT statement, using a Visual FoxPro 9 database! I can't manage to create XML files from Visual FoxPRo! I want some help getting started in this area! I am a beginner!
User avatar
wriedmann
Posts: 3807
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Remove empty lines from XML file

Post by wriedmann »

Hi Danut,
unfortunately this is not a VFP forum.
X# is a Xbase compiler that has also compatibility with VFP, but is not compatible at 100% - it is a completely different product.
There are some VFP users here, but it does not seem they can help you with your issue.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1610
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: Remove empty lines from XML file

Post by FFF »

Well, now you are on another topic? As far as i found, SAFT is NOT a statement, but a concept, how to structure your app.

Anyway - you may have in an xml file as many empty lines as you like, they are silently ignored by any processing - that's part of it's appeal...

Finally: when one posts for the first time in a foreign forum, it's good manners to start with some word's describing what you do, what's your background, what you need, and even a name to talk to wouldn't hurt - makes it easier to help :)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
kevclark64
Posts: 131
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

Re: Remove empty lines from XML file

Post by kevclark64 »

It's extremely easy to create an XML file from a table in Visual Foxpro:

Code: Select all

adapter = CREATEOBJECT("XMLAdapter")
USE mytable
adapter.AddTableSchema("mytable")
adapter.ToXML("xmloutput.xml",,.t.)
That copies all the data from a table to an XML file. If you want to do something different from that there are other options.

I strongly suggest posting your general foxpro questions at https://www.foxite.com/
Post Reply