owner element should allow any content
According to RFC 4918, Section 14.17, the owner element "MAY be extended with child elements, mixed content, text content or attributes".
I guess, that the best way to support this would be converting owner to an XElement and adding a [XmlAnyElement(Name = WebDavConstants.Owner, Namespace = "DAV:")] attribute.
Wouldn't this be a so called dead property?
This is what the spec says: The value provided MUST be treated as a dead property in terms of XML Information Item preservation.
IOW: It must be treated like a dead property, but it isn't one.
Another possibility would be to use an ExtensionDataObject in the class OwnerHref, see here: http://stackoverflow.com/questions/8520228/using-xmlanyelement
Then, any unknown content is stored in a special property.
Does this work with mixed content and attributes too?
I'll try to get a unit test in place. If I get this right, the server returns (as as example):
Content-Type: text/xml; charset="utf-8"
Content-Length: xxx
<?xml version="1.0" encoding="utf-8" ?>
<D:multistatus xmlns:D="DAV:">
<D:response>
<D:href>http://www.example.com/papers/</D:href>
<D:propstat>
<D:prop>
<D:owner>
<D:href>http://www.example.com/users/jd</D:href>
<x:author xmlns:x='http://example.com/ns'>
<x:name>Jane Doe</x:name>
<!-- Jane's contact info -->
<x:uri type='email' added='2005-11-26'>mailto:[email protected]</x:uri>
<x:uri type='web' added='2005-11-27'>http://www.example.com</x:uri>
<x:notes xmlns:h='http://www.w3.org/1999/xhtml'>
Jane has been working way <h:em>too</h:em> long on the
long-awaited revision of <![CDATA[<RFC2518>]]>.
</x:notes>
</x:author>
</D:owner>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>```
The server may also return
<D:owner xmlns:x='urn:other-schema-provider:other-schema' x:myattr='test-attr'>
Test
<x:whatever>test</x:whatever>
</D:owner>
I didn't have much time today, but I've tried to implement it (sorry, it's a bit quick & dirty): See branch: https://github.com/DecaTec/Portable-WebDAV-Library/tree/owner-element-with-any-content
A unit test can be found in the NetFX part: \netfx\unittests\decatec.webdav.netfx.unittest\unittestwebdavresponsecontentparser.cs
Now an OwnerHref instance can contain any content (next to the Href, this will stay). But due to being an XElement, it more or less raw XML.
Could you please have a look? Do you have any special use case where you'll need that feature?
It's slightly better, but it still doesn't allow the owner content I posted in my previous comment. It might be OK for most users and I only see one situation where your current solution isn't good enough:
When you do a lockdiscovery and get the owner of an active lock of a different user using a different WebDAV client that stores the owner like this: <D:owner>owner-name</D:owner>.
TBH: I'd really break compatibility and scrap the owner object and replace it with a single XElement. Breaking compatibility at a version <1.0 shouldn't be a huge problem.
I've tried to provide the owner as XElement, but ran into another problem:
The main reason for introducing the "object model" was that the client won't have to fiddle around with raw XML. By the need of specifying the owner as XElement, this solution wasn't straightforward in the first place.
My next approach: On LockInfo and ActiveLock, there are two properties now:
OwnerHref: This is treated like the "old"OwnerHref, i.e. an owner can be specified by href (e.g. e mail address), this is only a string valueOwnerRaw: This gives you the rawXElementwith all its contents (to be used with mixed content, etc.)
You can find the changes in the "owner branch": https://github.com/DecaTec/Portable-WebDAV-Library/tree/owner-element-with-any-content
I've also put up some unit tests for testing the examples from this issue.
The only drawback is when getting the OwnerRaw, the namespace prefixes for "DAV:" are missing ("D:").
But this way you should get all the information needed. Would you mind to take another look if this solution will fit your needs?
Edit: Unit tests for the new implementation can be found in UnitTestWebDavResponseContentParser.cs (NetFx and UWP)
@fubar-coder: Do the changes fit your needs or is there still something missing?
I wasn't able to test the changes yet, sorry.
I have just tested this version with our code and this suits our needs. :shipit:
Setting OwnerHref doesn't work. It fails with the following exception: System.Xml.XmlException : The ':' character, hexadecimal value 0x3A, cannot be included in a name.. I tried to set it with:
new LockInfo()
{
LockScope = LockScope.CreateExclusiveLockScope(),
LockType = LockType.CreateWriteLockType(),
OwnerHref = "http://localhost/uri-owner",
}
OK, I'll fix the exception with invalid chars and prepare a new version then.
Just created a PR to fix this issue.
Thanks for contributing! I've merged all into the main branch and will put together a new version of the lib tomorrow.
Prepared and released update. NuGet package should be available soon.