(define-module (ldp resource sxml) #:use-module (ldp resource) #:use-module (ldp path) #:use-module (sxml match)) (define-public (sxml->resource res) (sxml-match res ((*TOP* (*PI* . ,whatever) . ,rest) (sxml->resource `(*TOP* ,@rest))) ((*TOP* ,rest) (sxml->resource rest)) ((https://linked-data-platform.planete-kraus.eu/ns:resource (@ (container "no") (uri-path ,uri-path) (etag ,etag) (content-type ,content-type))) (make-resource (string->path uri-path) etag (string->symbol content-type) #f)) ((https://linked-data-platform.planete-kraus.eu/ns:resource (@ (container "yes") (uri-path ,uri-path) (etag ,etag) (content-type ,content-type)) (https://linked-data-platform.planete-kraus.eu/ns:contains (@ (path ,contents))) ...) (make-resource (string->path uri-path) etag (string->symbol content-type) (map string->path contents))) (,otherwise (scm-error 'wrong-type-arg "sxml->resource" "Expected a SXML fragment with the correct schema, not ~s." (list res) (list res))))) (define-public (resource->sxml x) `(*TOP* (*PI* xml "version=\"1.0\" encoding=\"utf-8\"") (resource (@ (xmlns "https://linked-data-platform.planete-kraus.eu/ns") (container ,(if (container? x) "yes" "no")) (uri-path ,(path->string (resource-path x))) (etag ,(resource-etag x)) (content-type ,(symbol->string (resource-content-type x)))) ,@(map (lambda (p) `(contains (@ (path ,(path->string p))))) (or (resource-contained x) '())))))