[Fix] retain namespaces and root attributes on round-trip; fixes #44#79
Merged
Merged
Conversation
ReqIF.ReadXml now captures each root attribute's namespace URI, and WriteNameSpaceAttributes (sync + async) emits prefixed non-namespace attributes such as xsi:schemaLocation correctly instead of passing the prefix where a namespace URI is expected; the sync and async write paths are aligned. The XHTML namespace declaration is no longer appended to the captured attribute list, so a ReqIF can be serialized more than once without accumulating duplicates. Also fixes ReqIFSerializer file output to use FileMode.Create instead of FileMode.OpenOrCreate: writing a shorter document over a longer existing file previously left trailing bytes, producing invalid XML when serializing to an existing destination. Adds NamespaceRetentionTestFixture covering xmlns declarations, prefixed attributes, async, and repeated serialization.
Adds data-driven round-trip tests over Datatype-Demo, ProR_Traceability-Template, DefaultValueDemo and reqifsharpgenerated (.reqif), and Spielwiese, requirements-and-objects and test-multiple-reqif (.reqifz, incl. async and the multi-document archive). Each asserts every root namespace declaration (and xml:lang / xsi:schemaLocation) present in the source is retained in the serialized output.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Fixes #44 — when a
.reqifwith custom namespaces is deserialized and serialized to a new destination, the declared namespaces (and other root attributes) should be retained.The capture/re-emit mechanism on the
REQ-IFroot already round-tripped the default andxmlns:*declarations, but it had real defects for prefixed, non-xmlnsattributes (e.g.xsi:schemaLocation) and lacked any test coverage. While adding that coverage, a latent file-output truncation bug was also surfaced and fixed.Changes
XmlAttributegains aNamespaceUri;ReqIF.ReadXml/ReadXmlAsyncstorereader.NamespaceURIfor each captured root attribute.WriteNameSpaceAttributes/WriteNameSpaceAttributesAsyncnow emit ordinary prefixed attributes (e.g.xsi:schemaLocation) using the captured namespace URI instead of passing the prefix where a namespace URI is expected. The sync and async paths are aligned (they previously diverged).attributes, so the sameReqIFcan be serialized repeatedly without accumulating duplicate declarations.FileMode.Createfor file output —ReqIFSerializer.Serialize/SerializeAsync(file overloads) usedFileMode.OpenOrCreate, which does not truncate; serializing a shorter document over a longer existing file left trailing bytes and produced invalid XML. Switched toFileMode.Create.Tests
New
NamespaceRetentionTestFixture(round-trips through deserialize → serialize → re-parse the root):xmlnsdefault +xmlns:configuration/xmlns:id/xmlns:xhtmlretained (sync and async).xmlns:xsi+xsi:schemaLocationprefixed attribute retained (fails before the fix).Verification
dotnet build ReqIFSharp.sln -c Release— 0 warnings / 0 errors.dotnet test ReqIFSharp.sln— 380 tests pass (296 core incl. 4 new, 84 extensions). The twoDefaultValueDemoround-trip-to-file tests, which exercised theOpenOrCreatepath, now pass.No
.csproj/ version changes.