feat(std/xml): Xml.decode reads a document into a typed value #573
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/570-xml-decode"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #570
Task
Step 3a of #78:
Xml().decode<T>(text)reads an XML document into aDecodetype with the default mapping, so an S3ListBucketResultdecodes into a type. Spec and decisions: #570.What
Two commits:
feat(encoding):ValueDecoder.of(..., singleAsList:)reads a value that is no sequence as a sequence of one, andNothingas an empty one. Default off;lenientalready did this and now implies the option, so existing behaviour is unchanged.feat(std/xml):Xml.decode, with the optionsnamingandstrict;XmlError.decodeFailed(line 0,cause()is theDecodeError). The tree becomes anEncodedValue(std/xml/src/decoder.trb, the layout ofToml.decode) and is read byValueDecoderwithlenient,singleAsList,naming,strict. Root element is the record (name not checked); a field is the child element of its name, else the attribute; names match on the local name; repeated children are a list;xmlnsdeclarations are no data.Docs:
xml.md,encoding.md, ENCODING.md (slice 8 status, decision 17),skills/regenerated.Two additions the acceptance criteria needed (in commit 2)
Naming.PascalCase(logLabelisLogLabel): a field starts with a lowercase letter and S3 names its elementsKeyCount,IsTruncated,ETag, so the S3 tests need a naming that spells them.ValueDecoder.string()underlenientrefuses a sequence, a mapping and a record instead of reading theirshow()text, so an element with child elements is an error for aStringfield (the failure with its field chain). No other std code useslenient.Seed: not touched (the compiler does not import
std/xml, no std name is looked up by string).Test
std/xml/tests/decode.test.trb(records from children, attributes and both; lists from repeated and single elements; Int/Float/Bool/Option; naming; strict on and off; default namespace; entity and CDATA; failure with field chain; recorded S3ListBucketResultandError),std/encoding/tests/single-as-list.test.trb,naming.test.trb,value-decoder.test.trb.torb test std/xml/tests/decode.test.trb std/encoding/tests: 78 passed, 0 failed;torb test std/xml/tests/xml.test.trb: 100 passed;torb format --check std/xml std/encoding: clean;sh tools/check-commits.sh origin/main HEAD: clean.sh tools/gates.sh ain forge CI (result in the first comment below).Xml.decodereads a document into a typed value (step 3a of #78) #570Xml.decodereads a document into a typed value (step 3a of #78) #5702c537e4aa65cced74ddbApproved. Checklist for
5cced74:std/xml/tests/decode.test.trbcovers every acceptance criterion of #570 (children/attributes/mix, repeated and single lists, Int/Float/Bool/Option, naming, strict on/off, default namespace, entity/CDATA, field chain, recorded S3ListBucketResultandError);single-as-list,namingandvalue-decodertests in std/encoding. CI is green on this head (tier A, bootstrap, gates, pdisc, commit messages).decoder.trbmatches the documented mapping (child beats attribute, local-name match,xmlnsskipped, repeated children become a sequence, empty root is an empty record).singleAsListis off by default andlenientstill implies it.PascalCase, thestring()refusal) are justified by the acceptance criteria in the PR body.parsedDocumentwithentityLimit; no new external access.skills/are updated; no new boundary.std/xmlis not imported by the compiler.Non-blocking:
lenient", which is not true:std/uri/src/route.trb:165,std/uri/src/template.trb:198andstd/regex/src/regex.trb:306useValueDecoder.of(..., lenient: true). Thestring()change reaches them only when a URI-template list variable (encodedFieldsOfyields aSequence,template.trb:476) is bound to aStringfield. It now fails, where it used to read theshow()text. That is arguably the better behaviour, but a one-line test instd/uri/testswould pin it.strictdoes not flag an attribute that a same-named child element shadows (decoder.trb, thenames.containsbranch). The document says the child wins, so this is consistent, but say so in thestricttext.Xml.encodewrites a typed value as an XML document (step 3b of #78) #605