41 if (!
$xml->hasAttribute(
'xml:lang')) {
42 throw new \Exception(
'Missing lang on Keywords.');
44 if (!is_string(
$xml->textContent) || !strlen(
$xml->textContent)) {
45 throw new \Exception(
'Missing value for Keywords.');
48 foreach (explode(
' ',
$xml->textContent) as $keyword) {
49 $this->
Keywords[] = str_replace(
'+',
' ', $keyword);
51 $this->lang =
$xml->getAttribute(
'xml:lang');
63 assert(is_string($this->lang));
66 $doc = $parent->ownerDocument;
68 $e = $doc->createElementNS(
Common::NS,
'mdui:Keywords');
69 $e->setAttribute(
'xml:lang', $this->lang);
71 foreach ($this->
Keywords as $keyword) {
72 if (strpos($keyword,
"+") !==
false) {
73 throw new \Exception(
'Keywords may not contain a "+" character.');
75 $value .= str_replace(
' ',
'+', $keyword) .
' ';
77 $value = rtrim($value);
78 $e->appendChild($doc->createTextNode($value));
79 $parent->appendChild($e);
toXML(\DOMElement $parent)
Convert this Keywords to XML.
__construct(\DOMElement $xml=null)
Initialize a Keywords.