On Wednesday, January 4, 2017 at 3:50:49 PM UTC-5, [email protected]
wrote:
>
> Hi Evert,
>
> thanks for the quick solution. I was able to download the updated package
> from GitHub and got it to work (however, I am still not able to install it
> via Composer - same error message as before).
>
> I am looking at your sabre\xml-atom reference implementation now. I may be
> mistaken, but as far as I can see you are parsing either (1) the values or
> (2) the attributes of elements. For exmpale:
>
> *(1) Value of an element*
> <title ">dive into mark</title>
>
> ...where "dive into mark" is the value of the "title" element
>
>
> *(2) Attribute of an element*
>
> <link rel="alternate" type="text/html"
> hreflang="en" href="http://example.org/"/>
>
> // where "http://example.org/" is the "href" attribute of the "link"
> element.
>
>
> However, as far as I can see you are not parsing both (1) the VALUE and
> (2) all ATTRIBUTES of the same singular element. For example:
>
> <title type="text">dive into mark</title>
>
> // where "dive into mark" is the value of the "title" element and "text"
> is the "type" attribute of the "title" element.
>
>
> I may miss the point somewhere, but that's my impression when I'm looking
> at "reading-test1.php" of your sabre/xml-atom package.
>
> How can you parse both the value and the attributes of the same element?
>
It depends a bit on what you are trying to parse it into. If your only goal
is to get a PHP array, you can simply not map the title element. The
default structure sabre/xml always give you for that element is this:
[
"name" => "title",
"value" => "dive into mark",
"attributes" => ["type" => "text"]
]
It's only when you use one of the default 'deserializers' that you get
different structures. In the sabre/xml-atom example there's two major ones
used:
1. The valueObject mapper, which is a standard sabre/xml built-in one that
maps PHP classes and properties to XML elements and child elements.
2. An attributeReader/attributeWriter which in the case of sabre/xml-atom
is a custom one.
So if you have an xml tag that you want to extract both an attribute and a
value from, and you hypothetically would want to map that to a PHP class
like this:
class Title {
public $title;
public $value;
}
The correct sabre/xml solution is to write a custom parser like this:
$server->elementMap['{myNamespace}title'] = function($reader) {
$result = new Title();
$result->type = $reader->getAttribute('type');
$result->value = $reader->readText();
$reader->next();
return $result;
};
--
You received this message because you are subscribed to the Google Groups
"SabreDAV Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sabredav-discuss/91a17718-1f96-4a67-9917-7987bb655cde%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.