Uploading KML files to SD card ESP32

Hi. Im trying to make a function to write a KML structure to a microSD card file, which looks something like this:

<Placemark id="1241D8CC911E32BFB2FD">
		<name>20KMH</name>
		<description><![CDATA[Date: 2021-11-07T11:52:21.000-0500<br />Longitude: 000<br />Latitude: 000<br />Speed: 20.56 KMH<br />Distance: 0.04km<br />Heading: 195 degrees<br />Elevation: 2697.00m<br />Accuracy: ~3m]]></description>
		<TimeStamp></TimeStamp>
		<styleUrl>#def_arrow</styleUrl>
		<Style>
			<IconStyle>
				<color>ccffff00</color>
				<heading>15</heading>
				<gx:headingMode>northUp</gx:headingMode>
			</IconStyle>
		</Style>
		<ExtendedData>
			<Data name="speed">
				<value>20.56 KMH</value>
			</Data>
			<Data name="heading">
				<value>195</value>
			</Data>
		</ExtendedData>
		<Point>
			<coordinates>000,000</coordinates>
		</Point>
	</Placemark>

I searched online about how to do this, and I found this code:

std::string FormatPlacemark(double lat1, double long1, double lat2, double long2)
{
    std::ostringstream ss;
    ss << "<Placemark>\n"
       << "<name>Path</name>\n"
       << "<description>This is the path between the 2 points</description>\n"
       << "<styleUrl>#pathstyle</styleUrl>\n"
       << "<LineString>\n"
       << "<tessellate>1</tessellate>\n"
       << "<coordinates>"
       << long1 << "," << lat1 << ",0"
       << " "
       << long2 << "," << lat2 << ",0"
       << "</coordinates>\n"
       << "</LineString>\n"
       << "</Placemark>\n";

    return ss.str();
}

The problem is that I dont know how to use it with the appendfile function of the library, since it always returns an error about std::ostringstream is not compatible with string type. Does anyone have any idea about how can I make that function? thanks

I am not clear whether you want to use Strings (uppercase S) or strings (lowercase s)

I want to create a string so that I can write it to the micro sd card, If you refer to the error, it is uppercase

Now I am even more confused

The partial error message that you posted says

No uppercase S there

Do you understand the difference between Strings (objects of the String library) and strings (zero terminated arrays of chars) ?

Is there really any need to create a single variable of either type to write to the SD card when you could split the write into separate steps, one for each section of the KML structure ?

Sorry to confuse you. What I want to do is to write that structure to a String, which then it will be written to the sd card each time a gps.decode() is available. How can I convert that structure to a string? that is my main question

It is possible to stupidly convert this function to a String type, although this is very inefficient.

String FormatPlacemark(double lat1, double long1, double lat2, double long2)
{
    String ss;
    ss = "<Placemark>\n"
       + "<name>Path</name>\n"
       + "<description>This is the path between the 2 points</description>\n"
       + "<styleUrl>#pathstyle</styleUrl>\n"
       + "<LineString>\n"
       + "<tessellate>1</tessellate>\n"
       + "<coordinates>"
       + String( long1) + "," + String( lat1) +  ",0 "
       + String(long2) + "," + String(lat2) + ",0"
       + "</coordinates>\n"
       + "</LineString>\n"
       + "</Placemark>\n";

    return ss;
}

Disclaimer - did not tested

It says invalid operands of types 'const char [13]' and 'const char [19]' to binary 'operator+'

String FormatPlacemark(double lat1, double long1, double lat2, double long2)
{
   String  ss("<Placemark>\n"
          "<name>Path</name>\n"
          "<description>This is the path between the 2 points</description>\n"
          "<styleUrl>#pathstyle</styleUrl>\n"
          "<LineString>\n"
          "<tessellate>1</tessellate>\n"
          "<coordinates>");
       ss+= String( long1) + String(",") + String( lat1) +  String(",0 ")
         + String(long2) + String(",") + String(lat2);
       ss+= String(",0 </coordinates>\n"
          "</LineString>\n"
          "</Placemark>\n");

    return ss;
}

You have done it again

String != string