Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for namespaces #4

Merged
merged 8 commits into from
Oct 19, 2023
Merged

Add support for namespaces #4

merged 8 commits into from
Oct 19, 2023

Conversation

daemontus
Copy link
Member

This PR adds support for namespaces in XmlChild using newly added methods in xml-doc.

Every XmlChild now has a namespace URL, such that the retrieved elements must match both name (as before) and the namespace URL (the URL is resolved through standard XML prefixes). When updating or creating a new XmlChild, the namespace is automatically set using the "closest" prefix that references the required namespace.

TODO: A similar mechanism still needs to be added to attributes. However, attributes follow slightly different resolution rules.

@codecov
Copy link

codecov bot commented Oct 2, 2023

Codecov Report

Attention: 97 lines in your changes are missing coverage. Please review.

Comparison is base (9322506) 44.94% compared to head (a21f511) 44.83%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #4      +/-   ##
==========================================
- Coverage   44.94%   44.83%   -0.11%     
==========================================
  Files          12       12              
  Lines         485      562      +77     
==========================================
+ Hits          218      252      +34     
- Misses        267      310      +43     
Files Coverage Δ
src/lib.rs 63.63% <100.00%> (-1.48%) ⬇️
src/xml/xml_element.rs 100.00% <100.00%> (+60.00%) ⬆️
src/xml/xml_property.rs 87.75% <100.00%> (ø)
src/sbase.rs 33.33% <50.00%> (ø)
src/xml/xml_list.rs 73.33% <78.57%> (-1.67%) ⬇️
src/xml/impl_xml_child.rs 43.47% <52.38%> (+0.62%) ⬆️
src/xml/xml_child.rs 54.16% <57.57%> (-15.40%) ⬇️
src/model.rs 7.14% <14.70%> (+1.34%) ⬆️
src/xml/xml_wrapper.rs 53.33% <51.21%> (-13.34%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@daemontus
Copy link
Member Author

PR is mostly ready for review. What changed:

  • Instead of From<XmlElement>, every XmlWrapper now has an unsafe unchecked_cast method. This change was mainly because we were using From in many places where it wasn't clear whether the conversion is safe. Now we still can convert between arbitrary wrapper types using the unchecked cast, but it is a bit more obvious and requires an unsafe block.
  • XmlElement::new has been renamed to new_raw to make it clear that this is a "low level" method.
  • The same holds for XmlWrapper::element. It is now called raw_element to highligher the fact that it is a "low level" method that should be used only when you know what you are doing.
  • XmlElement::new_quantified was added. Using this method, we can now create a new element with a namespace in a proper "detached" state.
  • Module constants::namespaces contains some URLs and default prefixes for the namespaces that we are using right now.
  • XmlChild::set type signature is now the same for both the optional and required child (although they perform slightly different safety checks). However, both implementations should now check that the name of the tag that you are updating is correct.
  • Methods clear and is_set are now only present in optional child. However, there is now clear_raw that is shared by all XmlChild implementations. Again, this is to clearly indicate that if you have a required child, clear is a low level operation that you should not take lightly.
  • I have added XmlDefault for SbmlModel and Compartment. We need to add this for all the remaining wrappers. But I think I will just make a macro that will do this for us.
  • Property namespace_url has been added along name where appropriate.
  • I made the basic minimum so that XmlList still works, but we probably need to talk about it a bit more (see Validate names/namespaces in XmlList #7).
  • The core of the new detach/attach process which respects namespaces is implemented in XmlWrapper::try_detach and XmlWrapper::try_attach_at.
  • This is still missing namespaces for properties/attributes, but I will try to do this as a separate PR.

Copy link
Contributor

@SolunarNexus SolunarNexus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All clear.

@SolunarNexus SolunarNexus merged commit bce4096 into main Oct 19, 2023
11 of 12 checks passed
@daemontus daemontus deleted the namespaces branch November 22, 2023 16:54
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.

2 participants