Validates a XML Element built form an Atom XML String and returns broken Atom Rules.
@access		protected
@param		XML_Element		$xmlElement		Root Element of Atom Feed
@return		bool
494423
protected function validate( $xmlElement )
	{
		$errors	= array();
		foreach( $xmlElement->getDocNamespaces() as $prefix => $namespace )
		{
			$prefix	= $prefix ? $prefix : "atom";
			$xmlElement->registerXPathNamespace( $prefix, $namespace );
		}
		$key	= "//atom:feed/";
		if( !count( $xmlElement->xpath( $key.'atom:author' ) ) )
			foreach( $xmlElement->entry as $entry )
				if( !$entry->author )
					$errors[]	= "feed_author";
		if( count( $xmlElement->xpath( $key.'atom:generator' ) ) > 1 )
			$errors[]	= "feed_generator";
		if( count( $xmlElement->xpath( $key.'atom:icon' ) ) > 1 )
			$errors[]	= "feed_icon";
		if( count( $xmlElement->xpath( $key.'atom:logo' ) ) > 1 )
			$errors[]	= "feed_logo";
		if( count( $xmlElement->xpath( $key.'atom:id' ) ) != 1 )
			$errors[]	= "feed_id";
		if( count( $xmlElement->xpath( $key.'atom:rights' ) ) > 1 )
			$errors[]	= "feed_rights";
		if( count( $xmlElement->xpath( $key.'atom:subtitle' ) ) > 1 )
			$errors[]	= "feed_subtitle";
		if( count( $xmlElement->xpath( $key.'atom:title' ) ) != 1 )
			$errors[]	= "feed_title";
		if( count( $xmlElement->xpath( $key.'atom:updated' ) ) != 1 )
			$errors[]	= "feed_updated";
		$ids	= array();
		foreach( $xmlElement->xpath( $key.'atom:link[@rel="alternate"]' ) as $link )
		{
			$id	= "";
			if( $link->hasAttribute( 'type' ) )
				$id	= $link->getAttribute( 'type' );
			if( $link->hasAttribute( 'hreflang' ) )
				$id	.= "_".$link->getAttribute( 'hreflang');
			if( in_array( $id, $ids ) )
			{
				$errors[]	= "feed_link_unique";
				break;
			}
			$ids[]	= $id;
		}

		$numberEntries	= count( $xmlElement->xpath( $key.'atom:entry' ) );
		for( $i=1; $i<=$numberEntries; $i++ )
		{
			$key	= "//atom:feed/atom:entry[$i]/";
			if( !count( $xmlElement->xpath( $key.'atom:author' ) ) && !count( $xmlElement->xpath( '//atom:feed/atom:author' ) ) )
				$errors[]	= "entry_author";
			if( count( $xmlElement->xpath( $key.'atom:content' ) ) > 1 )
				$errors[]	= "entry_content";
			if( count( $xmlElement->xpath( $key.'atom:id' ) ) != 1 )
				$errors[]	= "entry_id";
			if( !count( $xmlElement->xpath( $key.'atom:content' ) ) && !count( $xmlElement->xpath( $key.'atom:link[@rel="alternate"]' ) ) )
				$errors[]	= "entry_link_alt";
			if( count( $xmlElement->xpath( $key.'atom:published' ) ) > 1 )
				$errors[]	= "entry_published";
			if( count( $xmlElement->xpath( $key.'atom:rights' ) ) > 1 )
				$errors[]	= "entry_rights";
			if( count( $xmlElement->xpath( $key.'atom:source' ) ) > 1 )
				$errors[]	= "entry_source";
			if( count( $xmlElement->xpath( $key.'atom:summary' ) ) > 1 )
				$errors[]	= "entry_summary";
			if( count( $xmlElement->xpath( $key.'atom:title' ) ) != 1 )
				$errors[]	= "entry_title";
			if( count( $xmlElement->xpath( $key.'atom:updated' ) ) != 1 )
				$errors[]	= "entry_updated";

			$keys	= array();
			foreach( $xmlElement->xpath( $key.'atom:link[@rel="alternate"]' ) as $link )
			{
				$key	= "";
				if( $link->hasAttribute( 'type' ) )
					$key	= $link->getAttribute( 'type' );
				if( $link->hasAttribute( 'hreflang' ) )
					$key	.= "_".$link->getAttribute( 'hreflang');
				if( in_array( $key, $keys ) )
				{
					$errors[]	= "entry_link_unique";
					break;
				}
				$keys[]	= $key;
			}
		}
		$this->errors	= $errors;

	}
908423
public function process(\DOMDocument $xml)
    {
        // matches:
        // - foo@bar.com
        // - <foo@bar.com>
        // - Some Name <foo@bar.com>
        // ignores leading and trailing whitespace
        // requires angled brackets when a name is given (that's what the
        //   two (?(1)) conditions do)
        // requires closing angled bracket if email address is given with an
        //   opening angled bracket but no name (that's what the (?(3))
        //   condition is for)
        $regex = '#^\s*(?P<name>[^<]+?)?\s*((?(1)<|<?)(?:mailto:)?'
            . '(?P<email>\b[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}\b)'
            . '(?(1)>|(?(3)>|>?)))\s*$#u';

        $xpath = new \DOMXPath($xml);
        $nodes = $xpath->query('//tag[@name="author"]/@description');

        /** @var \DOMElement $node */
        foreach ($nodes as $node) {
            // FIXME: #193
            if (preg_match($regex, $node->nodeValue, $matches)) {
                if ($matches['name']) {
                    $value = $matches['name'];
                } else {
                    // in case there were <> but no name... this cleans up the
                    // output a bit
                    $value = $matches['email'];
                }

                $node->nodeValue = $value;

                /** @var \DOMElement $parentNode */
                $parentNode = $node->parentNode;
                $parentNode->setAttribute(
                    'link',
                    'mailto:' . $matches['email']
                );
            }
        }

        return $xml;
    }
286482
private static function convertNode(XMLElement $element, DOMNode $node)
    {
        if ($node->hasAttributes()) {
            foreach ($node->attributes as $name => $attrEl) {
                $element->setAttribute($name, General::sanitize($attrEl->value));
            }
        }

        if ($node->hasChildNodes()) {
            foreach ($node->childNodes as $childNode) {
                if ($childNode instanceof DOMCdataSection) {
                    $element->setValue(General::wrapInCDATA($childNode->data));
                } elseif ($childNode instanceof DOMText) {
                    if ($childNode->isWhitespaceInElementContent() === false) {
                        $element->setValue(General::sanitize($childNode->data));
                    }
                } elseif ($childNode instanceof DOMElement) {
                    self::convert($element, $childNode);
                }
            }
        }
    }
139613
protected function loadElementsFromXmlFileWithPath($xmlFile, $nodePath)
    {
        $xml = file_get_contents($xmlFile);
        // Remove whitespaces between closing tag and opening tag.
        $xml = preg_replace('/>\s+</', '><', $xml);

        $doc = new \DOMDocument();
        $doc->loadXML($xml);

        $xpath = new \DOMXpath($doc);
        $elements = $xpath->query($nodePath);

        return $elements;
    }
794406
private static function deserializeRequiredClaims($xmlElement)
    {
        $result = [];

        foreach ($xmlElement->children() as $child) {
            if (!isset($child->ClaimType)) {
                throw new  \RuntimeException("The TokenClaim must contains a 'ClaimType' element");
            }

            $claim = new TokenClaim((string) $child->ClaimType);

            if (isset($child->ClaimValue)) {
                $claim->setClaimValue((string) $child->ClaimValue);
            }
            $result[] = $claim;
        }

        return $result;
    }
1122046
private function buildXml(array $array, \SimpleXMLElement &$xmlElem):\SimpleXMLElement
    {
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                if (!is_numeric($key)) {
                    $subnode = $xmlElem->addChild("$key");
                    $this->buildXml($value, $subnode);
                } else {
                    $subnode = $xmlElem->addChild("item$key");
                    $this->buildXml($value, $subnode);
                }
            } else {
                $xmlElem->addChild("$key", htmlspecialchars("$value"));
            }
        }
        return ($xmlElem);
    }
446349
public function fromXml(SimpleXMLElement $xmlElement)
    {
        $classname = $this->xmlElementToClassname($xmlElement);
        if (!is_null($classname)) {
            $return = new $classname();
            if ($return instanceof ArrayObject) {
                foreach ($xmlElement as $xmlChild) {
                    $return->append($this->fromXml($xmlChild));
                }
            } else {
                $objectData = array();
                foreach ($xmlElement as $xmlChild) {
                    $key = $this->xmlkeyToProperty($xmlChild->getName());
                    if (isset($objectData[$key])) {
                        if (!is_array($objectData[$key])) {
                            $objectData[$key] = array($objectData[$key]);
                        }
                        $objectData[$key][] = $this->fromXml($xmlChild);
                    } else {
                        $objectData[$key] = $this->fromXml($xmlChild);
                    }
                }
                $return->setData($objectData, false);
            }
        } else {
            $return = $this->castValue($xmlElement);
        }

        return $return;
    }
179465
def validateElement(self, doc, elem):
        
        if doc is None: doc__o = None
        else: doc__o = doc._o
        if elem is None: elem__o = None
        else: elem__o = elem._o
        ret = libxml2mod.xmlValidateElement(self._o, doc__o, elem__o)
        return ret
280143
def validateElement(self, ctxt, elem):
        
        if ctxt is None: ctxt__o = None
        else: ctxt__o = ctxt._o
        if elem is None: elem__o = None
        else: elem__o = elem._o
        ret = libxml2mod.xmlValidateElement(ctxt__o, self._o, elem__o)
        return ret
743272
private static function deserializeTokenVerificationKey($xmlElement)
    {
        if (!isset($xmlElement->attributes(Resources::XSI_XML_NAMESPACE)->type)) {
            throw new \RuntimeException("A TokenVerificationKey must contains a 'type' attribute");
        }

        $type = $xmlElement->attributes(Resources::XSI_XML_NAMESPACE)->type;

        if ($type == 'SymmetricVerificationKey') {
            if (!isset($xmlElement->KeyValue)) {
                throw new \RuntimeException("The SymmetricVerificationKey must contains an 'KeyValue' element");
            }

            $key = new SymmetricVerificationKey();
            $key->setKeyValue(base64_decode($xmlElement->KeyValue));

            return $key;
        }

        if ($type == 'X509CertTokenVerificationKey') {
            if (!isset($xmlElement->RawBody)) {
                throw new \RuntimeException("The X509CertTokenVerificationKey must contains a 'RawBody' element");
            }

            $key = new X509CertTokenVerificationKey();
            $key->setRawBody(base64_decode($xmlElement->RawBody));

            return $key;
        }

        throw new \RuntimeException("Unknown TokenVerificationKey type: type='{$type}'");
    }
1041868
protected function validateCategoryLinks(SimpleXMLElement $xml)
    {
        $categoryIdElements = $xml->xpath('/tweakwise/categories/category/categoryid');
        $categoryIds = array();
        foreach ($categoryIdElements as $id) {
            $categoryIds[] = (string) $id;
        }
        $categoryIds = array_flip($categoryIds);

        foreach ($xml->xpath('/tweakwise/categories/category/parents/categoryid') as $categoryIdElement) {
            $categoryId = (string) $categoryIdElement;
            if (!isset($categoryIds[$categoryId])) {
                throw new ValidationException(__(sprintf('Category parent reference %s not found', $categoryId)));
            }
        }

        foreach ($xml->xpath('/tweakwise/items/item/categories/categoryid') as $categoryIdElement) {
            $categoryId = (string) $categoryIdElement;
            if (!isset($categoryIds[$categoryId])) {
                throw new ValidationException(__(sprintf('Product category reference %s not found', $categoryId)));
            }
        }
    }
976746
protected function serializeElement(DOMElement $element)
	{
		$php     = '';
		$elName  = $element->getAttribute('name');
		$id      = $element->getAttribute('id');
		$isVoid  = $element->getAttribute('void');

		// Test whether this element name is dynamic
		$isDynamic = (bool) (strpos($elName, '{') !== false);

		// PHP representation of this element's name
		$phpElName = $this->convertAttributeValueTemplate($elName);

		// NOTE: the element name is escaped by default to account for dynamically-generated names
		$phpElName = 'htmlspecialchars(' . $phpElName . ',' . ENT_QUOTES . ')';

		// If the element name is dynamic, we cache its name for convenience and performance
		if ($isDynamic)
		{
			$varName = '$e' . $id;

			// Add the var declaration to the source
			$php .= $varName . '=' . $phpElName . ';';

			// Replace the element name with the var
			$phpElName = $varName;
		}

		// Test whether this element is void if we need this information
		if ($isVoid === 'maybe')
		{
			$php .= '$v' . $id . '=preg_match(' . var_export(TemplateParser::$voidRegexp, true) . ',' . $phpElName . ');';
		}

		// Open the start tag
		$php .= "\$this->out.='<'." . $phpElName . ';';

		// Serialize this element's content
		$php .= $this->serializeChildren($element);

		// Close that element unless we know it's void
		if ($isVoid !== 'yes')
		{
			$php .= "\$this->out.='</'." . $phpElName . ".'>';";
		}

		// If this element was maybe void, serializeCloseTag() has put its content within an if
		// block. We need to close that block
		if ($isVoid === 'maybe')
		{
			$php .= '}';
		}

		return $php;
	}
1315789
public static function convertFromXMLString($root_element, $xml)
    {
        $doc = new DOMDocument('1.0', 'utf-8');
        $doc->loadXML($xml);

        return self::convertFromDOMDocument($root_element, $doc);
    }
447414
public function validateSchemaVersion($xml)
    {
        libxml_use_internal_errors(true);

        try {
            $theSchema = self::getSchemaVersion($xml);
            $doiXML = new \DOMDocument();
            $doiXML->loadXML($xml);
        } Catch (\Exception $e) {
            $this->validationMessage = $e->getMessage();
            return false;
        }

        $schemaPath = SchemaProvider::getSchema($theSchema);

        // if the schema is not stored locally, lookup on datacite
        if (!is_file($schemaPath)) {
            $schemaPath = 'http://schema.datacite.org/meta' . $theSchema;
        }

        $result = $doiXML->schemaValidate($schemaPath);

        foreach (libxml_get_errors() as $error) {
            $this->validationMessage = $error->message;
        }
        return $result;
    }
187054
public function validate( $xml )
	{
		$parser	= xml_parser_create();
		$dummy	= create_function( '', '' );
		xml_set_element_handler( $parser, $dummy, $dummy );
		xml_set_character_data_handler( $parser, $dummy );
		if( !xml_parse( $parser, $xml ) )
		{
			$msg	= "%s at line %d";
			$error	= xml_error_string( xml_get_error_code( $parser ) );
			$line	= xml_get_current_line_number( $parser );
			$this->error['message']	= sprintf( $msg, $error, $line );
			$this->error['line']	= $line;
			$this->error['xml']		= $xml;
			xml_parser_free( $parser );
			return FALSE;
		}
		xml_parser_free( $parser );
		return TRUE;
	}
820
public function xml2array(\SimpleXMLElement $xml)
    {
        $arr = array();
        foreach ($xml as $element) {
            $tag = $element->getName();
            $e = get_object_vars($element);
            if (!empty($e)) {
                $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e;
            } else {
                $arr[$tag] = trim($element);
            }
        }

        return $arr;
    }
695361
public function parseXml($xmlString)
    {
        Validate::notNull($xmlString, 'xmlString');
        Validate::isString($xmlString, 'xmlString');
        $atomLinkXml = simplexml_load_string($xmlString);
        $attributes = $atomLinkXml->attributes();

        if (!empty($attributes['href'])) {
            $this->href = (string) $attributes['href'];
        }

        if (!empty($attributes['rel'])) {
            $this->rel = (string) $attributes['rel'];
        }

        if (!empty($attributes['type'])) {
            $this->type = (string) $attributes['type'];
        }

        if (!empty($attributes['hreflang'])) {
            $this->hreflang = (string) $attributes['hreflang'];
        }

        if (!empty($attributes['title'])) {
            $this->title = (string) $attributes['title'];
        }

        if (!empty($attributes['length'])) {
            $this->length = (int) $attributes['length'];
        }

        $undefinedContent = (string) $atomLinkXml;
        if (empty($undefinedContent)) {
            $this->undefinedContent = null;
        } else {
            $this->undefinedContent = (string) $atomLinkXml;
        }
    }