Page 1 of 1
Remove empty lines from XML file
Posted: Tue Jan 28, 2025 12:51 pm
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!
Re: Remove empty lines from XML file
Posted: Tue Jan 28, 2025 2:03 pm
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.
Re: Remove empty lines from XML file
Posted: Tue Jan 28, 2025 5:41 pm
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/
Re: Remove empty lines from XML file
Posted: Tue Jan 28, 2025 7:55 pm
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!
Re: Remove empty lines from XML file
Posted: Tue Jan 28, 2025 10:14 pm
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
Re: Remove empty lines from XML file
Posted: Tue Jan 28, 2025 10:24 pm
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
Re: Remove empty lines from XML file
Posted: Wed Jan 29, 2025 2:30 pm
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/