refactor: Refactor XML node classes and introduce NodeContainer - #18
Merged
Conversation
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>
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.
No description provided.