Skip to content

[Fix] read ReqIF documents without whitespace between elements; fixes #94 - #96

Merged
samatstariongroup merged 1 commit into
developmentfrom
GH94
Oct 18, 2026
Merged

samatstariongroup merged 1 commit into
developmentfrom
GH94

Conversation

@samatstariongroup

Copy link
Copy Markdown
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the ReqIFSharp code style guidelines
  • I have provided test coverage for my change (where applicable)

Description

Fixes #94.

A ReqIF document without whitespace between its elements (minified XML) lost data without an error. ReadElementContentAsString moves the reader past the end tag, so in a while (reader.Read()) loop the next Read() skipped the following sibling:

  • every other ReqIFHeader field (such as CREATION-TIME and REQ-IF-TOOL-ID) was empty;
  • every other ENUM-VALUE-REF of an enumeration attribute value was missing;
  • the spec relations of a relation group were not read, or an XmlException was thrown.

Changes

  • New internal XmlReaderExtensions.ReadElementContentAsStringToEndElement (and ...Async): reads the text content of the element and leaves the reader on its end tag (or on the element when it is empty). It throws an XmlException, with line information when available, when the element contains child elements.
  • ReqIFHeader, AttributeValueEnumeration (ENUM-VALUE-REF) and RelationGroup (SPEC-RELATION-REF) use it, sync and async.
  • RelationGroup reads SPEC-RELATIONS through a subtree reader instead of ReadStartElement/ReadEndElement. Only direct children are read. A child other than SPEC-RELATION-REF is skipped with a warning and the references after it are read; before, it caused an XmlException. The schema allows only SPEC-RELATION-REF there.
  • The other ReadElementContentAs* and ReadInnerXml calls in the library were checked: each reads the only child of a wrapper element or reads through a subtree, and is not affected.

Tests

  • MinifiedDocumentTestFixture:
    • minified copies of the test documents read to the same object graph as the originals, as .reqif and .reqifz;
    • every header field of a minified header is read, also after empty fields;
    • a relation group with two spec relations, with SPEC-RELATIONS last and before TYPE, an empty SPEC-RELATIONS, and an unsupported child (warning logged, nested reference not read), indented and minified.
  • XmlReaderExtensionsTestFixture: text, CDATA and comments, empty elements, whitespace before the element, child elements, wrong position, and the line information in the exception.
  • Shared helpers moved from PrefixedNamespaceTestFixture into TestDocuments.
  • All tests run sync and async. dotnet build -c Release: 0 warnings; dotnet test: 436 passed.

Found during the review, tracked separately: #95 (THE-ORIGINAL-VALUE is not read).

🤖 Generated with Claude Code

…94

ReadElementContentAsString moves the reader past the end tag. Inside a
while (reader.Read()) loop the next Read then skips the following sibling
when no whitespace separates the elements, so minified documents lost
every other header field and enumeration value, and the spec relations of
a relation group were not read or caused an XmlException.

- Add XmlReaderExtensions.ReadElementContentAsStringToEndElement(Async),
  which reads the text content and leaves the reader on the end tag.
- Use it in ReqIFHeader, for ENUM-VALUE-REF in AttributeValueEnumeration
  and for SPEC-RELATION-REF in RelationGroup.
- Read SPEC-RELATIONS through a subtree reader. A child other than
  SPEC-RELATION-REF is skipped with a warning; before, it caused an
  XmlException.
- Add MinifiedDocumentTestFixture and XmlReaderExtensionsTestFixture, and
  move the shared test-document helpers into TestDocuments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@samatstariongroup
samatstariongroup merged commit 87a66c4 into development Oct 18, 2026
8 checks passed
@samatstariongroup
samatstariongroup deleted the GH94 branch October 18, 2026 17:02
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.

[Bug]: Elements are skipped when a ReqIF document has no whitespace between elements

1 participant