Skip to content

Conversation

@FeepingCreature
Copy link
Collaborator

Switch XML decoder to stream parsing.

@FeepingCreature FeepingCreature force-pushed the feature/xml-stream-parser branch 5 times, most recently from 5368e1e to d86737e Compare February 28, 2025 12:30
@FeepingCreature FeepingCreature force-pushed the feature/xml-stream-parser branch from d86737e to 2630191 Compare February 28, 2025 12:33

decode!Value(`<Value><A a="5"/><B b="3"/></Value>`).should.throwAn!XmlException
(`Element "Value": contained more than one of "A", "B"`);
(`"this.builder.field": found more than one kind of element of "A", "B" in [A(5), B(3)]`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message with “element” and “kind” and “[]” looks rather cryptic.

xmllint complains in the first case that A or B is missing.
And in the second case that B is not expected. The choice is made by the first A.

}

// when
auto value = decode!Container(`<Container>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that namespaces are difficult. In the root element they are declared like this:
xmlns:ns2="http://www.ifopt.org.uk/acsb" xmlns:ns3="http://www.ifopt.org.uk/ifopt" xmlns:ns4="http://datex2.eu/schema/2_0RC1/2_0"

Here, ns2, ns3, ns4 could also be foo, bar, baz. Then ns2:MobilityImpairedAccess actually stands for {http://www.ifopt.org.uk/acsb}MobilityImpairedAccess.

If the deserializer does not support this, a delimiting comment would be appropriate.

module text.xml.Decode;

import boilerplate.util : udaIndex;
import boilerplate.util : optionallyRemoveTrailingUnderline, udaIndex;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problematic function name has already been introduced with boilerplate. There, the function requires a comment...

I would have preferred what instead of how. Claude suggests normalizeFieldName, for example. Then the detail of whether the underscore is added to the front or back, or whether we put "a" or "my" in front of the field name, remains a boilerplate secret.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW: "enum field with underscore" is the test case for optionallyRemoveTrailingUnderline
(the "underline" instead of "underscore" was what made me stumble over the meaningfulness of the function name)

What's the matter with foo_? If there is another enum member foo?

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