Skip to content

refactor: Refactor XML node classes and introduce NodeContainer - #18

Merged
XenoSnowFox merged 5 commits into
mainfrom
refactor/xml-nodes
Aug 29, 2026
Merged

refactor: Refactor XML node classes and introduce NodeContainer#18
XenoSnowFox merged 5 commits into
mainfrom
refactor/xml-nodes

Conversation

@XenoSnowFox

Copy link
Copy Markdown
Contributor

No description provided.

XenoSnowFox and others added 5 commits August 29, 2026 12:11
Rename and reorganize XML node classes and add a container node type.

- Rename XmlDeclarationTag -> DeclarationNode and XmlTextContent -> TextNode.
- Remove legacy XmlTagNode and add TagNode (now inherits NodeContainer).
- Introduce NodeContainer (new) to own children, serialize them, and prevent cycles when appending.
- Extend INode with parent tracking (getParent/setParent) and make NodeContainer a friend.
- Add NodeType::CONTAINER.
- Provide operator<< overloads for appending/serialization and keep XML escaping/validation logic.

These changes centralize child-management, simplify cycle detection, and standardize naming.
IAttributes::setAttribute was made virtual so nodes can override attribute assignment. DeclarationNode now overrides setAttribute to restrict attributes to 'version', 'encoding', and 'standalone', validating allowed values and throwing std::invalid_argument on errors. serialize() was simplified to assume a validated state and requires a 'version' attribute.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rename the TextNode method `content(std::string)` to `setContent(std::string)` in include/xtrpg/xml/node/TextNode.hpp to improve naming consistency. Behavior and validation are unchanged (still throws std::invalid_argument for invalid XML characters). Note: this is an API change — update any callers that used the old method name.
Change forEachAttribute to use a boolean-returning callback so callers can control iteration. The callback signature was updated from void(std::string_view key, std::string_view value) to bool(std::string_view key, std::string_view value); returning true continues iteration, false breaks early. Implementation and doc comment updated accordingly. Note: this is a small API change — update existing callbacks to return a bool.
Defaulted copy/move constructors and copy/move assignment operators for DeclarationNode, TagNode, and TextNode to restore implicit copy/move behavior and reduce boilerplate. Added a default constructor for IAttributes. Cleaned up NodeContainer constructors' formatting and defaulted its destructor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@XenoSnowFox
XenoSnowFox merged commit a815f2a into main Aug 29, 2026
4 checks passed
@XenoSnowFox
XenoSnowFox deleted the refactor/xml-nodes branch August 29, 2026 02:36
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.

1 participant