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

Design for namespaces #316

Closed
mohe2015 opened this issue Aug 30, 2021 · 1 comment
Closed

Design for namespaces #316

mohe2015 opened this issue Aug 30, 2021 · 1 comment
Labels
enhancement namespaces Issues related to namespaces support serde Issues related to mapping from Rust types to XML

Comments

@mohe2015
Copy link

Also the namespace thing is probably not a final fix. Although I don't know XML really well I think we would need some mapping from namespace urls. Let me give an example (CalDAV):

<?xml version="1.0" encoding="utf-8"?>
<d:propfind xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:nc="http://nextcloud.org/ns" xmlns:oc="http://owncloud.org/ns" xmlns:s="http://sabredav.org/ns">
  <d:prop xmlns:x1="http://apple.com/ns/ical/" xmlns:x2="http://nextcloud.com/ns">
    <d:current-user-principal />
  </d:prop>
</d:propfind>

should as far as I understand it should be equivalent to:

<?xml version="1.0" encoding="utf-8"?>
<dav:propfind xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:dav="DAV:" xmlns:nc="http://nextcloud.org/ns" xmlns:oc="http://owncloud.org/ns" xmlns:s="http://sabredav.org/ns">
  <dav:prop xmlns:x1="http://apple.com/ns/ical/" xmlns:x2="http://nextcloud.com/ns">
    <dav:current-user-principal />
  </dav:prop>
</dav:propfind>

The way yaserde implements this is you specify a mapping of namespace-shorthands to namespace urls:

#[yaserde(
    namespace = "d: DAV:",
    namespace = "s: http://sabredav.org/ns",
    namespace = "cal: urn:ietf:params:xml:ns:caldav",
    namespace = "cs: http://calendarserver.org/ns/",
    namespace = "oc: http://owncloud.org/ns",
    namespace = "nc: http://nextcloud.org/ns"
)]

and then can use these shorthands. A potentially easier but maybe also annoying way would be to directly use the url maybe like:

#[serde(rename = "$unflatten=urn:ietf:params:xml:ns:caldav href")]

where we should choose delimiters as invalid characters of the namespace url. But then you would need to store all xmlns: attributes on a stack or so to know which shorthand this belongs to.

Originally posted by @mohe2015 in #306 (comment)

@Mingun Mingun added enhancement serde Issues related to mapping from Rust types to XML namespaces Issues related to namespaces support labels May 21, 2022
@Mingun
Copy link
Collaborator

Mingun commented May 25, 2022

I have a clearer vision how namespaces should be supported in the Deserializer. I'm working on that, so I close this as duplicate of #218

@Mingun Mingun closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement namespaces Issues related to namespaces support serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants