Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support optional start elements in xmlstreamwriter. #1193

Merged
merged 2 commits into from
Oct 27, 2023

Conversation

tsteven4
Copy link
Collaborator

this adds methods to xmlstreamwriter to allow conditional writing of a start element. The conditional element will only be written to the stream if it has children, which is deteremined when the condtional element is ended. This simplifies writing of such elements as the writer does not need to know if it will subsequently write children or not.

This is groundwork for further possible improvements in the gpx writer extension handling. For example, we merge garmin_fs_xml_fprint and gpx_write_common_extensions, only writing the extensions when gpx garminextensions option is selected? Another example is the use of TrackPointExtension v2 instead of v1, allowing speed and course to be written in gpx 1.1. Shouldn't we make the default gpx write version 1.1, it has been out since 8/2004!

this adds methods to xmlstreamwriter to allow conditional writing
of a start element.  The conditional element will only be written to
the stream if it has children, which is deteremined when the condtional
element is ended.  This simplifies writing of such elements as the
writer does not need to know if it will subsequently write children or
not.
@tsteven4
Copy link
Collaborator Author

I think this fixes one or more bugs related to the current necessity to check to see if we have data for every possible extension element we might want to write before we write the extensions element. Then, subsequently we also have to check if we have data for each extension element to see if we should write it. Even if there isn't a bug that dual checking is hard to maintain.

@tsteven4
Copy link
Collaborator Author

@robertlipe this is groundwork for my desire to move garmin_fs_xml_fprint into GpxFormat::gpx_write_common_extensions, and only write the garmin extensions when the gpx option garminextensions is enabled. This will simplify the decision tree in GpxFormat::gpx_waypt_pr. Today we either do passthrough, or print one subset of the garmin extensions(garmin_fs_xml_fprint), or print a different subset of the garmin extensions(gpx_write_common_extensions) based on the existence of gmsd data, and the value of the garminextensions and humminbirdextensions options. For the reasons in my preceding comment I think this PR is desirable by itself, but it is also blocking my desires explained in this comment. Are you ok with this PR? You can review my potential consolidation in an upcoming PR if this PR is accepted.

@robertlipe
Copy link
Collaborator

Agreed all around.
This is better than what we have, but we're heading into an unscalable tangle. I agree, unsurprisingly, that your proposed path if moving that logic into the printer and let it decide when to spill a tag.

@tsteven4
Copy link
Collaborator Author

I don't see a scalability problem with the number of wpts/rtepts/trkpts. As soon as the startOptionalElement is paired with a endElement that stack is destructed. In our usage all stack usage is contained is bounded by an extensions element. And I would argue the extensions element content is finite.

@tsteven4 tsteven4 merged commit c95e1cf into GPSBabel:master Oct 27, 2023
20 checks passed
@tsteven4 tsteven4 deleted the xmlwritestack branch October 27, 2023 20:07
@GPSBabelDeveloper
Copy link
Collaborator

GPSBabelDeveloper commented Oct 27, 2023 via email

@tsteven4
Copy link
Collaborator Author

See #1200.

I think it is easier to understand when we write what for waypoints, it is now simply controlled by the gpx writer extension options.

Any unrecognized tags go through tt_unknown on read. This does mean we have to catch all tags from the gpx namespace so they don't go through tt_unknown. We added some missing ones in #1191. This set is finite, but if new elements are added to gpx 1.2 they could cause problems. We might be able to guard against this by checking the namespace. It would be easy to handle this in gpx 1.1 because all the foreign stuff is within gpx extension tags. But gpx 1.0 isn't so kind.

@robertlipe
Copy link
Collaborator

robertlipe commented Oct 27, 2023 via email

@tsteven4
Copy link
Collaborator Author

Your correct, we probably still take some liberties assuming prefixes are associated with the expected namespaces. On gpx read we do attempt to map some namespaces to the expected prefix used in the tags (GpxFormat::qualifiedName()). I also suspect if we had a gpx file where the gpx namespace used a prefix we would crash and burn.

I have been considering using more of the namespace support in QXmlStreamWriter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants