/** * Load XML schema string * * @param string $xmlSchema */ protected function loadSchema($xmlSchema) { $this->doc = new \DOMDocument(); $this->doc->loadXML(mb_convert_encoding($xmlSchema, $this->encoding, mb_detect_encoding($xmlSchema))); $this->xpath = new \DOMXPath($this->doc); $this->xpath->registerNamespace($this->namespacePrefix, $this->xmlSchemaNamespace); }
/** * @param $templateName * @param DoubleClickDistributionProfile $profile * @param $distributionProfile */ public function __construct($templateName, DoubleClickDistributionProfile $profile) { $xmlTemplate = realpath(dirname(__FILE__) . '/../') . '/xml/' . $templateName; $this->distributionProfile = $profile; $this->doc = new KDOMDocument('1.0', 'UTF-8'); $this->doc->formatOutput = true; $this->doc->preserveWhiteSpace = false; $this->doc->load($xmlTemplate); $this->xpath = new DOMXPath($this->doc); $this->xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/'); $this->xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); $this->xpath->registerNamespace('openSearch', 'http://a9.com/-/spec/opensearchrss/1.0/'); $this->xpath->registerNamespace('dfpvideo', 'http://api.google.com/dfpvideo'); // item node template $node = $this->xpath->query('/rss/channel/item')->item(0); $this->item = $node->cloneNode(true); $node->parentNode->removeChild($node); // content node template $node = $this->xpath->query('media:group/media:content', $this->item)->item(0); $this->content = $node->cloneNode(true); $node->parentNode->removeChild($node); // thumbnail node template $node = $this->xpath->query('media:group/media:thumbnail', $this->item)->item(0); $this->thumbnail = $node->cloneNode(true); $node->parentNode->removeChild($node); // category node template $node = $this->xpath->query('media:group/media:category', $this->item)->item(0); $this->category = $node->cloneNode(true); $node->parentNode->removeChild($node); // set profile properties $this->setNodeValue('/rss/channel/title', $profile->getChannelTitle()); $this->setNodeValue('/rss/channel/description', $profile->getChannelDescription()); $this->setNodeValue('/rss/channel/link', $profile->getChannelLink()); $this->setItemsPerPage($profile->getItemsPerPage()); }
function testOne() { $doc = new \DOMDocument(); $doc->load(__DIR__ . '/../../../../../../../resources/sample/Response/response01.xml'); $xpath = new \DOMXPath($doc); $xpath->registerNamespace('samlp', Protocol::SAML2); $xpath->registerNamespace('ds', Protocol::NS_XMLDSIG); $xpath->registerNamespace('a', Protocol::NS_ASSERTION); $list = $xpath->query('/samlp:Response/a:Assertion/ds:Signature'); $this->assertEquals(1, $list->length); /** @var $signatureNode \DOMElement */ $signatureNode = $list->item(0); $signatureValidator = new SignatureXmlValidator(); $signatureValidator->loadFromXml($signatureNode); $list = $xpath->query('./ds:KeyInfo/ds:X509Data/ds:X509Certificate', $signatureNode); $this->assertEquals(1, $list->length); /** @var $signatureNode \DOMElement */ $certificateDataNode = $list->item(0); $certData = $certificateDataNode->textContent; $certificate = new X509Certificate(); $certificate->setData($certData); $key = KeyHelper::createPublicKey($certificate); $ok = $signatureValidator->validate($key); $this->assertTrue($ok); }
/** * Parse the xrds file in the argument. The xrds description must have been * fetched via curl or something else. * * TODO: more robust checking, support for more service documents * TODO: support for URIs to definition instead of local xml:id * * @param string data contents of xrds file * @exception Exception when the file is in an unknown format * @return array */ function xrds_parse($data) { $oauth = array(); $doc = @DOMDocument::loadXML($data); if ($doc === false) { throw new Exception('Error in XML, can\'t load XRDS document'); } $xpath = new DOMXPath($doc); $xpath->registerNamespace('xrds', 'xri://$xrds'); $xpath->registerNamespace('xrd', 'xri://$XRD*($v*2.0)'); $xpath->registerNamespace('simple', 'http://xrds-simple.net/core/1.0'); // Yahoo! uses this namespace, with lowercase xrd in it $xpath->registerNamespace('xrd2', 'xri://$xrd*($v*2.0)'); $uris = xrds_oauth_service_uris($xpath); foreach ($uris as $uri) { // TODO: support uris referring to service documents outside this one if ($uri[0] == '#') { $id = substr($uri, 1); $oauth = xrds_xrd_oauth($xpath, $id); if (is_array($oauth) && !empty($oauth)) { return $oauth; } } } return false; }
public function merge() { $filename = "{$this->result_dir}/docProps/app.xml"; $dom = new \DOMDocument(); $dom->load($filename); /* * => in HeadingPairs/vt:vector/vt:variant[2] set <vt:i4> to {N} => in TitlesOfParts/vt:vector set attribute 'size' to {N} => add <vt:lpstr>{New sheet}</vt:lpstr> */ $xpath = new \DOMXPath($dom); $xpath->registerNamespace("m", "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"); $xpath->registerNamespace("mvt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); $elems = $xpath->query("//m:HeadingPairs/mvt:vector/mvt:variant[2]/mvt:i4"); foreach ($elems as $e) { $e->nodeValue = $this->sheet_number; } $elems = $xpath->query("//m:TitlesOfParts/mvt:vector"); foreach ($elems as $e) { $e->setAttribute('size', $this->sheet_number); $tag = $dom->createElement('vt:lpstr'); $tag->nodeValue = $this->sheet_name; $e->appendChild($tag); } $dom->save($filename); }
/** * Creates a new style extractor for the given $odt document. * * @param DOMDocument $odt */ public function __construct(DOMDocument $odt) { $this->odt = $odt; $this->xpath = new DOMXpath($odt); $this->xpath->registerNamespace('style', ezcDocumentOdt::NS_ODT_STYLE); $this->xpath->registerNamespace('text', ezcDocumentOdt::NS_ODT_TEXT); }
/** * @param Set $set * @param string $path */ public function __construct(Set $set, $path) { $this->set = $set; $this->path = $path; $this->dom = new \DOMDocument(); $this->dom->load($path); $xpath = new \DOMXPath($this->dom); $xpath->registerNamespace('link', 'http://www.xbrl.org/2003/linkbase'); $xpath->registerNamespace('linkbase', 'http://www.xbrl.org/2003/linkbase'); $lls = array(); /** @var $element \DOMElement */ foreach ($xpath->evaluate('//link:linkbase/*') as $element) { switch ($element->nodeName) { case 'labelLink': $lls[] = new Label\Link($this, $element); break; case 'referenceLink': $lls[] = new Reference\Link($this, $element); break; case 'presentationLink': $lls[] = new Presentation\Link($this, $element); break; case 'calculationLink': $lls[] = new Calculation\Link($this, $element); break; case 'definitionLink': $lls[] = new Definition\Link($this, $element); break; } } $this->links = $lls; }
private function initRepository() { $this->repository = new \DOMDocument('1.0', 'UTF-8'); $this->repository->load(__DIR__ . '/../templates/phive.xml'); $this->xp = new \DOMXPath($this->repository); $this->xp->registerNamespace('phive', 'https://phar.io/repository'); }
/** * @param $templateName * @param $distributionProfile */ public function __construct($templateName) { $xmlTemplate = realpath(dirname(__FILE__) . '/../') . '/xml/' . $templateName; $this->doc = new KDOMDocument(); $this->doc->formatOutput = true; $this->doc->preserveWhiteSpace = false; $this->doc->load($xmlTemplate); $this->xpath = new DOMXPath($this->doc); $this->xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/'); $this->xpath->registerNamespace('dcterms', 'http://purl.org/dc/terms/'); $this->xpath->registerNamespace('cim', 'http://labs.comcast.net/cim_mrss/'); // item node template $node = $this->xpath->query('/rss/channel/item')->item(0); $this->item = $node->cloneNode(true); $node->parentNode->removeChild($node); // content node template $node = $this->xpath->query('media:group/media:content', $this->item)->item(0); $this->content = $node->cloneNode(true); $node->parentNode->removeChild($node); // thumbnail node template $node = $this->xpath->query('media:group/media:thumbnail', $this->item)->item(0); $this->thumbnail = $node->cloneNode(true); $node->parentNode->removeChild($node); // category node template $node = $this->xpath->query('media:group/media:category', $this->item)->item(0); $this->category = $node->cloneNode(true); $node->parentNode->removeChild($node); }
private function checkRequestXml(\DOMDocument $doc, $id) { //$xml = $doc->saveXML(); //print "\n\n$xml\n\n"; $xpath = new \DOMXPath($doc); $xpath->registerNamespace('samlp', Protocol::SAML2); $xpath->registerNamespace('saml', Protocol::NS_ASSERTION); $list = $xpath->query('/samlp:AuthnRequest'); $this->assertEquals(1, $list->length); /** @var $node \DOMElement */ $node = $list->item(0); $this->assertEquals($id, $node->getAttribute('ID')); $this->assertEquals('2.0', $node->getAttribute('Version')); $this->assertEquals($this->destination, $node->getAttribute('Destination')); $this->assertEquals($this->ascURL, $node->getAttribute('AssertionConsumerServiceURL')); $this->assertEquals($this->protocolBinding, $node->getAttribute('ProtocolBinding')); $list = $xpath->query('/samlp:AuthnRequest/saml:Issuer'); $this->assertEquals(1, $list->length); /** @var $node \DOMElement */ $node = $list->item(0); $this->assertEquals($this->issuer, $node->textContent); $list = $xpath->query('/samlp:AuthnRequest/samlp:NameIDPolicy'); $this->assertEquals(1, $list->length); /** @var $node \DOMElement */ $node = $list->item(0); $this->assertEquals($this->nameIDPolicyFormat, $node->getAttribute('Format')); $this->assertEquals('true', $node->getAttribute('AllowCreate')); }
/** * addEntriesFromFeed adds all the entries from a zotero api feed to the collection * @param $feed either a DOMDocument or string xml of the feed */ public function addEntriesFromFeed($feed) { if (is_string($feed)) { $dom = new DOMDocument(); //cleanup GET param separators in the links in the feed $feed = str_replace('&', '&', $feed); $dom->loadXML($feed); } else { if (get_class($feed) == 'DOMDocument') { $dom = $feed; //$newFeedNode = $dom->importNode($feed, true); //$dom->appendChild($newFeedNode); } else { throw new Exception('Entry must be either an XML string or an ATOM feed DOMNode'); } } $xpath = new DOMXPath($dom); $xpath->registerNamespace('zxfer', 'http://zotero.org/ns/transfer'); $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); $entryNodes = $xpath->query('//atom:entry'); for ($i = 0; $i < $entryNodes->length; $i++) { $newEntry = new phpZoteroEntry($entryNodes->item($i)); $this->entries[$newEntry->itemUri] = $newEntry; } }
/** * Processes read records * @param $data the xml data to process */ function record_reader($data) { // prepare insert and delete statements: $ins_stm = $this->dbh->prepare('INSERT INTO data (oaiid, datestamp, assigned_identifier) VALUES (?, ?, ?);'); $del_stm = $this->dbh->prepare('DELETE FROM data WHERE oaiid=?;'); if (!($xpath = new DOMXPath($data))) { throw new OAIHarvesterException('Cannot create DOMXPath'); } $xpath->registerNamespace('OAI20', OAIServiceProvider::OAI20_XML_NAMESPACE); $xpath->registerNamespace('OAIDC', 'http://www.openarchives.org/OAI/2.0/oai_dc/'); $xpath->registerNamespace('DC', 'http://purl.org/dc/elements/1.1/'); if (!($oai_identifier = $xpath->query('//OAI20:record/OAI20:header/OAI20:identifier')->item(0)->nodeValue)) { throw new OAIHarvesterException('Missing identifier in record header'); } if (!($oai_datestamp = $xpath->query('//OAI20:record/OAI20:header/OAI20:datestamp')->item(0)->nodeValue)) { throw new OAIHarvesterException('Missing datestamp in record header'); } date_default_timezone_set('UTC'); // stupid PHP $timestamp = strtotime($oai_datestamp); $this->_log("Reading record <{$oai_identifier}>, datestamp <{$oai_datestamp}> (={$timestamp})"); $this->dbh->beginTransaction(); $del_stm->execute(array($oai_identifier)); // delete existent records for this oaiid // now write new entries for each found identifier: foreach ($xpath->query('//OAI20:record/OAI20:metadata/OAIDC:dc/DC:identifier') as $identifier_node) { $dc_identifier = $orig_id = trim($identifier_node->nodeValue); $this->_log("Found DC:Identifier <{$dc_identifier}>"); if (false !== strpos($dc_identifier, ' ')) { // identifier contains spaces, so it possibly is some other kind of metadata $this->_log("ignored identifier, since it doesn't seem to be a technical one."); continue; } elseif (preg_match('/^[0-9]{4}-[0-9]{3}[0-9X]/', $dc_identifier)) { // identifier is an ISSN (we guess so....) $dc_identifier = 'urn:issn:' . $dc_identifier; // RFC3044 } elseif (preg_match('/^([0-9]-?){9}[0-9X]/', $dc_identifier)) { // identifier is an ISBN-10 (we think...) $dc_identifier = 'urn:isbn:' . $dc_identifier; // RFC3187 } elseif (preg_match('/^([0-9]-?){12}[0-9]/', $dc_identifier)) { // identifier is an ISBN-13 (probably) $dc_identifier = 'urn:isbn:' . $dc_identifier; // RFC3187 } elseif (preg_match('/^10.[0-9]+\\/[^\\/].*/', $dc_identifier)) { // identifier is a DOI (as it seems) $dc_identifier = 'doi:' . $dc_identifier; // doi: is a registered URI scheme } elseif (!preg_match('/^[0-9a-zA-Z]+:.*/', $dc_identifier)) { // identifier is not a URI, so we ignore it for now $this->_log('identifier is not a URI, ignoring...'); continue; } if ($dc_identifier != $orig_id) { $this->_log("Transformed identifier to <{$dc_identifier}>"); } $ins_stm->execute(array($oai_identifier, $timestamp, $dc_identifier)); } $this->dbh->commit(); }
/** * Create an instance of Zend_Service_Amazon_ResultSet and create the necessary data objects * * @param DOMDocument $dom * @return void */ public function __construct(DOMDocument $dom) { $this->_dom = $dom; $this->_xpath = new DOMXPath($dom); $this->_xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2011-08-01'); $this->_results = $this->_xpath->query('//az:Item'); }
private function setupXPath($document) { $xpath = new DOMXPath($document); $xpath->registerNamespace("db", "http://icinga.org/icinga/config/global/api/views/1.0"); $xpath->registerNamespace("ae", "http://agavi.org/agavi/config/global/envelope/1.0"); return $xpath; }
/** * @param $templateName * @param $distributionProfile */ public function __construct($templateName) { $xmlTemplate = realpath(dirname(__FILE__) . '/../') . '/xml/' . $templateName; $this->doc = new KDOMDocument(); $this->doc->formatOutput = true; $this->doc->preserveWhiteSpace = false; $this->doc->load($xmlTemplate); //namespaces $this->xpath = new DOMXPath($this->doc); $this->xpath->registerNamespace('live', 'http://live.com/schema/media/'); $this->xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/'); $this->xpath->registerNamespace('abcnews', 'http://abcnews.com/content/'); // item node template $node = $this->xpath->query('/rss/channel/item')->item(0); $this->item = $node->cloneNode(true); $node->parentNode->removeChild($node); // thumbnail node template $node = $this->xpath->query('media:thumbnail', $this->item)->item(0); $this->thumbnail = $node->cloneNode(true); $node->parentNode->removeChild($node); // category node template $node = $this->xpath->query('media:category', $this->item)->item(0); $this->category = $node->cloneNode(true); $node->parentNode->removeChild($node); }
/** * @return \DOMNodeList */ public function getLinkbases() { $xPath = new \DOMXPath($this->dom); $xPath->registerNamespace('xsd', 'http://www.w3.org/2001/XMLSchema'); $xPath->registerNamespace('link', 'http://www.xbrl.org/2003/linkbase'); $xPath->registerNamespace('xlink', 'http://www.w3.org/1999/xlink'); return $xPath->evaluate("//xsd:schema/xsd:annotation/xsd:appinfo/link:linkbaseRef/@xlink:href"); }
function get_nameid() { $xpath = new DOMXPath($this->xml); $xpath->registerNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol"); $xpath->registerNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion"); $query = "/samlp:Response/saml:Assertion/saml:Subject/saml:NameID"; $entries = $xpath->query($query); return $entries->item(0)->nodeValue; }
private function SignDomDocument($domDocument) { //create xPath $xPath = new \DOMXPath($domDocument); //register namespaces to use in xpath query's $xPath->registerNamespace('wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'); $xPath->registerNamespace('sig', 'http://www.w3.org/2000/09/xmldsig#'); $xPath->registerNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/'); //Set id on soap body to easily extract the body later. $bodyNodeList = $xPath->query('/soap:Envelope/soap:Body'); $bodyNode = $bodyNodeList->item(0); $bodyNode->setAttribute('Id', '_body'); //Get the digest values $controlHash = $this->CalculateDigestValue($this->GetCanonical($this->GetReference('_control', $xPath))); $bodyHash = $this->CalculateDigestValue($this->GetCanonical($this->GetReference('_body', $xPath))); //Set the digest value for the control reference $Control = '#_control'; $controlHashQuery = $query = '//*[@URI="' . $Control . '"]/sig:DigestValue'; $controlHashQueryNodeset = $xPath->query($controlHashQuery); $controlHashNode = $controlHashQueryNodeset->item(0); $controlHashNode->nodeValue = $controlHash; //Set the digest value for the body reference $Body = '#_body'; $bodyHashQuery = $query = '//*[@URI="' . $Body . '"]/sig:DigestValue'; $bodyHashQueryNodeset = $xPath->query($bodyHashQuery); $bodyHashNode = $bodyHashQueryNodeset->item(0); $bodyHashNode->nodeValue = $bodyHash; //Get the SignedInfo nodeset $SignedInfoQuery = '//wsse:Security/sig:Signature/sig:SignedInfo'; $SignedInfoQueryNodeSet = $xPath->query($SignedInfoQuery); $SignedInfoNodeSet = $SignedInfoQueryNodeSet->item(0); //Canonicalize nodeset $signedINFO = $this->GetCanonical($SignedInfoNodeSet); //Sign signedinfo with privatekey $signature2; openssl_sign($signedINFO, $signature2, $this->pemdata); //Add signature value to xml document $sigValQuery = '//wsse:Security/sig:Signature/sig:SignatureValue'; $sigValQueryNodeset = $xPath->query($sigValQuery); $sigValNodeSet = $sigValQueryNodeset->item(0); $sigValNodeSet->nodeValue = base64_encode($signature2); //Get signature node $sigQuery = '//wsse:Security/sig:Signature'; $sigQueryNodeset = $xPath->query($sigQuery); $sigNodeSet = $sigQueryNodeset->item(0); //Create keyinfo element and Add public key to KeyIdentifier element $KeyTypeNode = $domDocument->createElementNS("http://www.w3.org/2000/09/xmldsig#", "KeyInfo"); $SecurityTokenReference = $domDocument->createElementNS('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'SecurityTokenReference'); $KeyIdentifier = $domDocument->createElement("KeyIdentifier"); $thumbprint = $this->sha1_thumbprint($this->pemdata); $KeyIdentifier->nodeValue = $thumbprint; $KeyIdentifier->setAttribute('ValueType', 'http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbPrintSHA1'); $SecurityTokenReference->appendChild($KeyIdentifier); $KeyTypeNode->appendChild($SecurityTokenReference); $sigNodeSet->appendChild($KeyTypeNode); }
/** * @param $templateName * @param $distributionProfile */ public function __construct($templateName) { $xmlTemplate = realpath(dirname(__FILE__) . '/../') . '/xml/' . $templateName; $this->doc = new KDOMDocument(); $this->doc->formatOutput = true; $this->doc->preserveWhiteSpace = false; $this->doc->load($xmlTemplate); $this->xpath = new DOMXPath($this->doc); $this->xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/'); $this->xpath->registerNamespace('dcterms', 'http://purl.org/dc/terms/'); $this->xpath->registerNamespace('pl', 'http://xml.theplatform.com/data/object'); $this->xpath->registerNamespace('pllist', 'http://xml.theplatform.com/data/list'); $this->xpath->registerNamespace('plfile', 'http://xml.theplatform.com/media/data/MediaFile'); $this->xpath->registerNamespace('plmedia', 'http://xml.theplatform.com/media/data/Media'); $this->xpath->registerNamespace('pla', 'http://xml.theplatform.com/data/object/admin'); $this->xpath->registerNamespace('twcable', 'http://twcable.com/customfields'); // item node template $node = $this->xpath->query('/rss/channel/item')->item(0); $this->item = $node->cloneNode(true); $node->parentNode->removeChild($node); // content node template $node = $this->xpath->query('media:group/media:content', $this->item)->item(0); $this->content = $node->cloneNode(true); $node->parentNode->removeChild($node); // category node template $node = $this->xpath->query('media:category', $this->item)->item(0); $this->category = $node->cloneNode(true); $node->parentNode->removeChild($node); }
/** * Filter ODT document. * * Filter for the document, which may modify / restructure a document and * assign semantic information bits to the elements in the tree. * * @param DOMDocument $document * @return DOMDocument */ public function filter(DOMDocument $document) { $xpath = new DOMXPath($document); $xpath->registerNamespace('office', ezcDocumentOdt::NS_ODT_OFFICE); $xpath->registerNamespace('draw', ezcDocumentOdt::NS_ODT_DRAWING); $binaries = $xpath->query('//draw:image/office:binary-data'); foreach ($binaries as $binary) { $this->extractBinary($binary); } return $document; }
/** * @param $templateName * @param $distributionProfile */ public function __construct($templateName) { $xmlTemplate = realpath(dirname(__FILE__) . '/../') . '/xml/' . $templateName; $this->doc = new KDOMDocument(); $this->doc->load($xmlTemplate); $this->xpath = new DOMXPath($this->doc); $this->xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/'); $this->xpath->registerNamespace('dcterms', 'http://purl.org/dc/terms/'); $node = $this->xpath->query('/rss/channel/item')->item(0); $this->item = $node->cloneNode(true); $node->parentNode->removeChild($node); }
/** * Gets the XPath object for this response * * @return DOMXPath the XPath object for response. */ public function getXPath() { if ($this->_xpath === null) { $document = $this->getDocument(); if ($document === false) { $this->_xpath = false; } else { $this->_xpath = new \DOMXPath($document); $this->_xpath->registerNamespace('sdb', $this->getNamespace()); } } return $this->_xpath; }
public function Elements($xpath) { $xpathEvaluator = new DOMXPath($this->ownerDocument); $xpathEvaluator->registerNamespace("svg", "http://www.w3.org/2000/svg"); $xpathEvaluator->registerNamespace("rbr", "http://www.brotherus.net"); $result = $xpathEvaluator->query($xpath, $this->domElement); $elements = array(); // empty array foreach ($result as $node) { $elements[] = new XElement($node); } return $elements; }
/** * */ private function init() { $this->dom = new \DOMDocument('1.0', 'UTF-8'); $this->dom->preserveWhiteSpace = false; $this->dom->formatOutput = true; if ($this->filename->exists()) { $this->dom->load($this->filename->asString()); } else { $this->dom->appendChild($this->dom->createElementNS($this->getNamespace(), $this->getRootElementName())); } $this->xPath = new \DOMXPath($this->dom); $this->xPath->registerNamespace('phive', $this->getNamespace()); }
/** * {@inheritdoc} */ protected function loadMetadataFromFile(\ReflectionClass $class, $file) { $classMetadata = new MergeableClassMetadata($class->getName()); // load xml file // TODO xsd validation $xmlDoc = XmlUtils::loadFile($file); $xpath = new \DOMXPath($xmlDoc); $xpath->registerNamespace('x', 'http://schemas.sulu.io/class/general'); $xpath->registerNamespace('list', 'http://schemas.sulu.io/class/list'); foreach ($xpath->query('/x:class/x:properties/x:*') as $propertyNode) { $classMetadata->addPropertyMetadata($this->getPropertyMetadata($xpath, $propertyNode, $class->getName())); } return $classMetadata; }
function createWPSRequest($parameters, $templatefilePath) { // check and give parameters default values // need this collection to be subscriptable $parray['interpolationMethod'] = isset($parameters->interpolationMethod) ? $parameters->interpolationMethod : "automatic"; $parray['calculationTime'] = isset($parameters->calculationTime) ? $parameters->calculationTime : "120000"; $parray['predictionTypes'] = isset($parameters->predictionTypes) ? $parameters->predictionTypes : "Mean"; $parray['propabilityLimit'] = isset($parameters->propabilityLimit) ? $parameters->propabilityLimit : "35i.4"; $parray['featureCollectionURL'] = isset($parameters->featureCollectionURL) ? $parameters->featureCollectionURL : ""; //FIXME: $parray['wfsURL'] = isset($parameters->wfsURL) ? $parameters->wfsURL : ""; //FIXME $parray['featureType'] = isset($parameters->featureType) ? $parameters->featureType : ""; //FIXME $parray['time'] = isset($parameters->time) ? $parameters->time : date("c"); //default to current time $parray['wpsURL'] = isset($parameters->wpsURL) ? $parameters->wpsURL : ""; $parray['outlierDetection'] = isset($parameters->outlierDetection) ? $parameters->outlierDetection : "true"; $parray['clipping'] = isset($parameters->clipping) ? $parameters->clipping : "true"; $parray['colorschema'] = isset($parameters->colorschema) ? $parameters->colorschema : ""; $parray['imageFormat'] = isset($parameters->imageFormat) ? $parameters->imageFormat : "image/jpeg"; $parray['bboxSRS'] = isset($parameters->bboxSRS) ? $parameters->bboxSRS : ""; $parray['bbox'] = isset($parameters->bbox) ? $parameters->bbox : ""; $parray['width'] = isset($parameters->width) ? $parameters->width : ""; $parray['height'] = isset($parameters->height) ? $parameters->height : ""; try { $WMCDoc = DOMDocument::load($templatefilePath); } catch (Exception $E) { new mb_exception("WMC XML is broken."); throw new Exception("Could not load WPS Template XML"); } if (!$WMCDoc) { throw new Exception("Could not load WPS Template XML"); } $xpath = new DOMXPath($WMCDoc); $xpath->registerNamespace("xlink", "http://www.w3.org/1999/xlink"); $xpath->registerNamespace("ows", "http://www.opengis.net/ows/1.1"); $xpath->registerNamespace("wps", "http://www.opengis.net/wps/1.0.0"); $OWS_IdentifierList = $xpath->query("/wps:Execute/wps:DataInputs/wps:Input/ows:Identifier"); $result = ""; foreach ($OWS_IdentifierList as $OWS_Identifier) { //FIXME: this requires that our data is checked above $WPS_LiteralDataList = $xpath->query("../wps:Data/wps:LiteralData", $OWS_Identifier); $WPS_LiteralData = $WPS_LiteralDataList->item(0); $WPS_LiteralData->nodeValue = $parray[$OWS_Identifier->nodeValue]; } $result = $WMCDoc->saveXML(); return $result; }
/** * @param string $assertionXpath * @return DOMNodeList */ protected function _queryAssertion($assertionXpath) { $xpath = new DOMXPath($this->document); $xpath->registerNamespace('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol'); $xpath->registerNamespace('saml', 'urn:oasis:names:tc:SAML:2.0:assertion'); $xpath->registerNamespace('ds', 'http://www.w3.org/2000/09/xmldsig#'); $signatureQuery = '//saml:Assertion/ds:Signature/ds:SignedInfo/ds:Reference'; $assertionReferenceNode = $xpath->query($signatureQuery)->item(0); if (!$assertionReferenceNode) { throw new Exception('Unable to query assertion, no Signature Reference found?'); } $id = substr($assertionReferenceNode->attributes->getNamedItem('URI')->nodeValue, 1); $nameQuery = "/samlp:Response/saml:Assertion[@ID='{$id}']" . $assertionXpath; return $xpath->query($nameQuery); }
/** * @param $templateName */ public function __construct($templateName) { $xmlTemplate = realpath(dirname(__FILE__) . '/../') . '/xml/' . $templateName; $this->doc = new KDOMDocument(); $this->doc->formatOutput = true; $this->doc->preserveWhiteSpace = false; $docLoadRes = $this->doc->load($xmlTemplate); $this->xpath = new DOMXPath($this->doc); $this->xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); $this->xpath->registerNamespace('go', 'http://hbogo.com/elements/1.0'); // item node template $node = $this->xpath->query('/atom:feed/atom:entry')->item(0); $this->item = $node->cloneNode(true); $node->parentNode->removeChild($node); }
private function _parseSvcDoc() { $client = new HTTPClient(); $response = $client->get($this->svcDocUrl); if ($response->getStatus() != 200) { throw new Exception("Can't get {$this->svcDocUrl}; response status " . $response->getStatus()); } $xml = $response->getBody(); $dom = new DOMDocument(); // We don't want to bother with white spaces $dom->preserveWhiteSpace = false; // Don't spew XML warnings to output $old = error_reporting(); error_reporting($old & ~E_WARNING); $ok = $dom->loadXML($xml); error_reporting($old); $path = new DOMXPath($dom); $path->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); $path->registerNamespace('app', 'http://www.w3.org/2007/app'); $path->registerNamespace('activity', 'http://activitystrea.ms/spec/1.0/'); $collections = $path->query('//app:collection'); for ($i = 0; $i < $collections->length; $i++) { $collection = $collections->item($i); $url = $collection->getAttribute('href'); $takesEntries = false; $accepts = $path->query('app:accept', $collection); for ($j = 0; $j < $accepts->length; $j++) { $accept = $accepts->item($j); $acceptValue = $accept->nodeValue; if (preg_match('#application/atom\\+xml(;\\s*type=entry)?#', $acceptValue)) { $takesEntries = true; break; } } if (!$takesEntries) { continue; } $verbs = $path->query('activity:verb', $collection); if ($verbs->length == 0) { $this->_addCollection(ActivityVerb::POST, $url); } else { for ($k = 0; $k < $verbs->length; $k++) { $verb = $verbs->item($k); $this->_addCollection($verb->nodeValue, $url); } } } }
/** * Unserializes the property. * * This static method should return a an instance of this object. * * @param \DOMElement $prop * @param array $propertyMap * @return DAV\IProperty */ static function unserialize(\DOMElement $prop, array $propertyMap) { $xpath = new \DOMXPath($prop->ownerDocument); $xpath->registerNamespace('d', 'urn:DAV'); // Finding the 'response' element $xResponses = $xpath->evaluate('d:response', $prop); $result = []; for ($jj = 0; $jj < $xResponses->length; $jj++) { $xResponse = $xResponses->item($jj); // Parsing 'href' $href = Href::unserialize($xResponse, $propertyMap); $properties = []; // Parsing 'status' in 'd:response' $responseStatus = $xpath->evaluate('string(d:status)', $xResponse); if ($responseStatus) { list(, $responseStatus, ) = explode(' ', $responseStatus, 3); } // Parsing 'propstat' $xPropstat = $xpath->query('d:propstat', $xResponse); for ($ii = 0; $ii < $xPropstat->length; $ii++) { // Parsing 'status' $status = $xpath->evaluate('string(d:status)', $xPropstat->item($ii)); list(, $statusCode, ) = explode(' ', $status, 3); $usedPropertyMap = $statusCode == '200' ? $propertyMap : []; // Parsing 'prop' $properties[$statusCode] = DAV\XMLUtil::parseProperties($xPropstat->item($ii), $usedPropertyMap); } $result[] = new Response($href->getHref(), $properties, $responseStatus ? $responseStatus : null); } return new self($result); }