private function declareService() { /** @var DomElement $serviceNode */ $serviceNode = $this->dom->getElementsByTagNameNS('*', 'service')->item(0); $name = $serviceNode->getAttribute('name'); $this->service = new Structure\ServiceStructure(['name' => $name, 'wsdl' => $this->wsdl, 'doc' => $this->serviceDescription]); }
public function GenerarXML() { $ruta_real = dirname(__FILE__); $PlantillaCFDI = $ruta_real . '\\CFDI_Factura.xml'; $PlantillaCFDIXML = fopen($PlantillaCFDI, "r"); $PlantillaXML = fread($PlantillaCFDIXML, filesize($PlantillaCFDI)); fclose($PlantillaCFDIXML); $XMLCFDI = new DomDocument(); $XMLCFDI->loadXML($PlantillaXML) or die("XML invalido"); $c = $XMLCFDI->getElementsByTagName('Comprobante')->item(0); $c->setAttribute('fecha', $this->fecha); if ($this->folio != '') { $c->setAttribute('folio', $this->folio); } if ($this->serie != '') { $c->setAttribute('serie', $this->serie); } if ($this->formadepago != '') { $c->setAttribute('formaDePago', $this->formadepago); } else { throw new Exception('Es obligatorio capturar el nodo "Forma de Pago"'); } if ($this->metododepago != '') { $c->setAttribute('metodoDePago', $this->metododepago); } else { throw new Exception('Es obligatorio capturar el nodo "Forma de Pago"'); } if ($this->lugardeexpedicion != '') { $c->setAttribute('LugarExpedicion', $this->lugardeexpedicion); } else { throw new Exception('Es obligatorio capturar el nodo "Lugar de expedición"'); } if ($this->cuentadepago != '') { $c->setAttribute('NumCtaPago', $this->cuentadepago); } else { $c->setAttribute('NumCtaPago', 'NO IDENTIFICADO'); } if ($this->tipocomprobante != '') { if (in_array($this->tipocomprobante, array("ingreso", "egreso", "traslado"))) { $c->setAttribute('tipoDeComprobante', $this->tipocomprobante); } else { throw new Exception('El tipo de comprobante solo puede ser de cualquiera de estos tres tipos: "ingreso", "egreso", "traslado"'); } } else { throw new Exception('Es obligatorio elegir el tipo de comprobante: ingreso, egreso, traslado'); } if ($this->moneda != "") { $c->setAttribute('moneda', $this->moneda); } if ($this->descuento > 0) { $c->setAttribute('descuento', Importe($this->descuento)); } if ($this->motivodescuento != "") { $c->setAttribute('motivoDescuento', $this->motivodescuento); } $NodoEmisor = $XMLCFDI->getElementsByTagName('Emisor')->item(0); $NodoEmisor->setAttribute("rfc", $this->emisor->rfc); $NodoEmisor->setAttribute("nombre", $this->emisor->razonsocial); if ($this->emisor->domicilio->calle != '' and $this->emisor->domicilio->colonia != '') { $NodoDomicilio_Emisor = $XMLCFDI->createElement('cfdi:DomicilioFiscal'); if ($this->emisor->domicilio->calle != '') { $NodoDomicilio_Emisor->setAttribute('calle', $this->emisor->domicilio->calle); } if ($this->emisor->domicilio->numeroexterior != '') { $NodoDomicilio_Emisor->setAttribute('noExterior', $this->emisor->domicilio->numeroexterior); } if ($this->emisor->domicilio->numerointerior != '') { $NodoDomicilio_Emisor->setAttribute('noInterior', $this->emisor->domicilio->numerointerior); } if ($this->emisor->domicilio->colonia != '') { $NodoDomicilio_Emisor->setAttribute('colonia', $this->emisor->domicilio->colonia); } if ($this->emisor->domicilio->localidad != '') { $NodoDomicilio_Emisor->setAttribute('localidad', $this->emisor->domicilio->localidad); } if ($this->emisor->domicilio->municipio != '') { $NodoDomicilio_Emisor->setAttribute('municipio', $this->emisor->domicilio->municipio); } if ($this->emisor->domicilio->codigopostal != '') { $NodoDomicilio_Emisor->setAttribute('codigoPostal', $this->emisor->domicilio->codigopostal); } if ($this->emisor->domicilio->estado != '') { $NodoDomicilio_Emisor->setAttribute('estado', $this->emisor->domicilio->estado); } if ($this->emisor->domicilio->pais != '') { $NodoDomicilio_Emisor->setAttribute('pais', $this->emisor->domicilio->pais); } $NodoEmisor->appendChild($NodoDomicilio_Emisor); } if ($this->emisor->regimenfiscal != '') { $NodoRegimenFiscal_Emisor = $XMLCFDI->createElement('cfdi:RegimenFiscal'); $NodoRegimenFiscal_Emisor->setAttribute('Regimen', $this->emisor->regimenfiscal); $NodoEmisor->appendChild($NodoRegimenFiscal_Emisor); } else { die('Debe existir un regimen fiscal para el emisor de la factura'); } $NodoReceptor = $XMLCFDI->getElementsByTagName('Receptor')->item(0); $NodoReceptor->setAttribute("rfc", $this->receptor->rfc); $NodoReceptor->setAttribute("nombre", $this->receptor->razonsocial); if ($this->receptor->domicilio->calle != '' and $this->receptor->domicilio->colonia != '') { $NodoDomicilio_Receptor = $XMLCFDI->createElement('cfdi:Domicilio'); if ($this->receptor->domicilio->calle != '') { $NodoDomicilio_Receptor->setAttribute('calle', $this->receptor->domicilio->calle); } if ($this->receptor->domicilio->numeroexterior != '') { $NodoDomicilio_Receptor->setAttribute('noExterior', $this->receptor->domicilio->numeroexterior); } if ($this->receptor->domicilio->numerointerior != '') { $NodoDomicilio_Receptor->setAttribute('noInterior', $this->receptor->domicilio->numerointerior); } if ($this->receptor->domicilio->colonia != '') { $NodoDomicilio_Receptor->setAttribute('colonia', $this->receptor->domicilio->colonia); } if ($this->receptor->domicilio->localidad != '') { $NodoDomicilio_Receptor->setAttribute('localidad', $this->receptor->domicilio->localidad); } if ($this->receptor->domicilio->municipio != '') { $NodoDomicilio_Receptor->setAttribute('municipio', $this->receptor->domicilio->municipio); } if ($this->receptor->domicilio->codigopostal != '') { $NodoDomicilio_Receptor->setAttribute('codigoPostal', $this->receptor->domicilio->codigopostal); } if ($this->receptor->domicilio->estado != '') { $NodoDomicilio_Receptor->setAttribute('estado', $this->receptor->domicilio->estado); } if ($this->receptor->domicilio->pais != '') { $NodoDomicilio_Receptor->setAttribute('pais', $this->receptor->domicilio->pais); } $NodoReceptor->appendChild($NodoDomicilio_Receptor); } $this->subtotal = 0; if (count($this->conceptos) > 0) { $NodoConceptos = $XMLCFDI->getElementsByTagName('Conceptos')->item(0); foreach ($this->conceptos as $conceptos) { $NodoConcepto = $XMLCFDI->createElement('cfdi:Concepto'); if ($conceptos->cantidad > 0) { $NodoConcepto->setAttribute("cantidad", $conceptos->cantidad); } else { die('El nodo concepto debe tener una cantidad especificada'); } if ($conceptos->unidad != "") { $NodoConcepto->setAttribute("unidad", $conceptos->unidad); } else { die('El nodo concepto debe tener una unidad especificada'); } if ($conceptos->descripcion != "") { $NodoConcepto->setAttribute("descripcion", $conceptos->descripcion); } else { die('El nodo concepto debe tener una descripción asignada'); } if ($conceptos->valorunitario > 0) { $NodoConcepto->setAttribute("valorUnitario", Importe($conceptos->valorunitario)); } else { die('El nodo valor unitario debe tener asignado un importe'); } $NodoConcepto->setAttribute("importe", Importe($conceptos->cantidad * $conceptos->valorunitario)); $NodoConceptos->appendChild($NodoConcepto); $this->subtotal = $this->subtotal + $conceptos->cantidad * $conceptos->valorunitario; } } if (count($this->impuestos) > 0) { $TotalImpuestosRetenidos = 0; $TotalImpuestosTrasladados = 0; $NodoImpuestos = $XMLCFDI->getElementsByTagName('Impuestos')->item(0); foreach ($this->impuestos as $impuesto) { if ($impuesto->tipo == _tiRetenido) { if ($XMLCFDI->getElementsByTagName('cfdi:Retenciones')->length > 0) { $NodoImpuestosRetenidos = $XMLCFDI->getElementsByTagName('cfdi:Retenciones')->item(0); } else { $NodoImpuestosRetenidos = $XMLCFDI->createElement('cfdi:Retenciones'); $NodoImpuestos->appendChild($NodoImpuestosRetenidos); } $NodoImpuestoRetenido = $XMLCFDI->createElement('cfdi:Retencion'); if ($impuesto->impuesto != "") { $NodoImpuestoRetenido->setAttribute('impuesto', $impuesto->impuesto); } else { die('El nodo impuesto retenido debe tener un valor en el atributo "impuesto"'); } // if($impuesto->tasa <> "") { // $NodoImpuestoRetenido->setAttribute('tasa', Importe($impuesto->tasa)); // } $NodoImpuestoRetenido->setAttribute('importe', Importe($impuesto->importe)); $NodoImpuestosRetenidos->appendChild($NodoImpuestoRetenido); $TotalImpuestosRetenidos = $TotalImpuestosRetenidos + $impuesto->importe; } if ($TotalImpuestosRetenidos > 0) { $NodoImpuestos->setAttribute('totalImpuestosRetenidos', Importe($TotalImpuestosRetenidos)); } } foreach ($this->impuestos as $impuesto) { if ($impuesto->tipo == _tiTrasladado) { if ($XMLCFDI->getElementsByTagName('cfdi:Traslados')->length > 0) { $NodoImpuestosTrasladados = $XMLCFDI->getElementsByTagName('cfdi:Traslados')->item(0); } else { $NodoImpuestosTrasladados = $XMLCFDI->createElement('cfdi:Traslados'); $NodoImpuestos->appendChild($NodoImpuestosTrasladados); } $NodoImpuestoTrasladado = $XMLCFDI->createElement('cfdi:Traslado'); if ($impuesto->impuesto != "") { $NodoImpuestoTrasladado->setAttribute('impuesto', $impuesto->impuesto); } else { die('El nodo impuesto trasladado debe tener un valor en el atributo "impuesto"'); } if ($impuesto->tasa != "") { $NodoImpuestoTrasladado->setAttribute('tasa', Importe($impuesto->tasa)); } $NodoImpuestoTrasladado->setAttribute('importe', Importe($impuesto->importe)); $NodoImpuestosTrasladados->appendChild($NodoImpuestoTrasladado); $TotalImpuestosTrasladados = $TotalImpuestosTrasladados + $impuesto->importe; } if ($TotalImpuestosTrasladados > 0) { $NodoImpuestos->setAttribute('totalImpuestosTrasladados', Importe($TotalImpuestosTrasladados)); } } } if ($this->subtotal > 0) { $c->setAttribute('subTotal', Importe($this->subtotal)); } // $descuentosporimpuestos = ($TotalImpuestosRetenidos + $TotalImpuestosTrasladados); // $descuentosporimpuestos = $TotalImpuestosRetenidos; $atributo_total = $this->subtotal - $TotalImpuestosRetenidos + $TotalImpuestosTrasladados - $this->descuento; $c->setAttribute('total', $atributo_total); $this->FacturaXML = $XMLCFDI->saveXML(); $XMLCFDI->normalizeDocument(); $XMLCFDI->formatOutput = true; if ($this->XMLSellado) { // $this->SellarXML_($XMLCFDI); $this->SellarXML_($this->FacturaXML); $c = $XMLCFDI->getElementsByTagNameNS('http://www.sat.gob.mx/cfd/3', 'Comprobante')->item(0); if ($this->sello == '') { throw new Exception('Ocurrió un error al intentar colocar el sello, no se registró ninguno'); } if ($this->certificado == '') { throw new Exception('Ocurrió un error al intentar colocar el certificado, no se registró ninguno'); } if ($this->numcertificado == '') { throw new Exception('Ocurrió un error al intentar colocar el número de certificado, no se registró ninguno'); } $c->setAttribute('sello', $this->sello); $c->setAttribute('certificado', $this->certificado); $c->setAttribute('noCertificado', $this->numcertificado); } $this->XMLNominaCFDI = $XMLCFDI->saveXML(); return $this->XMLNominaCFDI; }
/** * Add the channel data * * @param \DomDocument $xmlDoc * @param array $channelData */ protected function addChannelData($channelData, $xmlDoc) { $xmlDoc->getElementsByTagName('generator')->item(0)->textContent = Feedster::FEED_GENERATOR_NAME; $xmlDoc->getElementsByTagName('lastBuildDate')->item(0)->textContent = date('r'); foreach ($channelData as $element => $elValue) { $xmlItem = $xmlDoc->getElementsByTagName($element)->item(0); if ($xmlItem instanceof \DOMElement) { $xmlItem->textContent = $elValue; } } $atomLink = $xmlDoc->getElementsByTagNameNS($xmlDoc->lookupNamespaceUri('atom'), 'link')->item(0); if ($atomLink instanceof \DOMElement) { $atomLink->setAttribute('href', isset($channelData['link']) ? $channelData['link'] : ''); } }
/** * Creates a new instance of the class by parsing dc_xml * @param string $dc_xml * @return Dublin_Core */ static function import_from_xml_string($dc_xml) { $dc_doc = new DomDocument(); if ($dc_doc->loadXML($dc_xml)) { $oai_dc = $dc_doc->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', '*'); $new_dc = new Dublin_Core(); foreach ($oai_dc as $child) { array_push($new_dc->dc[$child->nodeName], $child->nodeValue); } return $new_dc; } else { return null; } }
public function __construct($xml) { if ($xml) { // first, lets find the cmis namespace to use $sx = new SimpleXMLElement($xml); $namespaces = $sx->getDocNamespaces(); unset($sx); $cmisra = isset($namespaces['cmisra']) ? $namespaces['cmisra'] : null; $cmis = isset($namespaces['cmis']) ? $namespaces['cmis'] : null; $doc = new DomDocument(); $doc->loadXML($xml); $versionElem = $doc->getElementsByTagNameNS($cmis, 'cmisVersionSupported'); if ($versionElem->item(0) == null) { // try 'versions'... knowledgetree has this misspelling $versionElem = $doc->getElementsByTagNameNS($cmis, 'cmisVersionsSupported'); } $version = 0; if ($versionElem && $versionElem->item(0)) { // use the first one... $version = $versionElem->item(0)->nodeValue; } $rootFolderElem = $doc->getElementsByTagNameNS($cmis, 'rootFolderId'); if ($rootFolderElem->item(0)) { $this->rootFolder = trim($rootFolderElem->item(0)->nodeValue); } $capabilities = $doc->getElementsByTagNameNS($cmis, 'capabilities'); if ($capabilities->item(0)) { foreach ($capabilities->item(0)->childNodes as $capNode) { if ($capNode->nodeName == '#text') { continue; } /* @var $capNode DomElement */ $this->capabilities[str_replace('cmis:', '', $capNode->nodeName)] = $capNode->nodeValue; } } $collectionElems = $doc->getElementsByTagName('collection'); foreach ($collectionElems as $collectionElem) { $aNs = $cmis; if ((double) $version >= 0.62) { $aNs = $cmisra; } $collectionType = $collectionElem->getAttributeNS($aNs, 'collectionType'); if (!$collectionType) { $collectionTypeElems = $collectionElem->getElementsByTagNameNS($cmisra, 'collectionType'); $collectionType = $collectionTypeElems->item(0)->nodeValue; } // protected against duplicate collections for now... there can be two urls for the // 'down' link, and we only want the 'children' one for now as it has more info // returned? if ($collectionType && !isset($this->collections[$collectionType])) { $this->collections[$collectionType] = $collectionElem->getAttribute('href'); } } $uriTemplates = $doc->getElementsByTagNameNS($cmisra, 'uritemplate'); if ($uriTemplates) { foreach ($uriTemplates as $uriTemplate) { $templateElem = $uriTemplate->getElementsByTagNameNS($cmisra, 'template'); $templateNameElem = $uriTemplate->getElementsByTagNameNS($cmisra, 'type'); $this->uritemplates[$templateNameElem->item(0)->nodeValue] = $templateElem->item(0)->nodeValue; } } unset($doc); } }
/** * Removes the given relationship from the item's RELS-EXT and re-saves it. * @param string $relationship * @param string $object */ function purge_relationship($relationship, $object) { $relsext = $this->get_datastream_dissemination('RELS-EXT'); $namespaceURI = 'info:fedora/fedora-system:def/relations-external#'; // Pre-pend a namespace prefix to recognized relationships switch ($relationship) { case 'rel:isMemberOf': case 'fedora:isMemberOf': $relationship = "isMemberOf"; $namespaceURI = 'info:fedora/fedora-system:def/relations-external#'; break; case "rel:isMemberOfCollection": case "fedora:isMemberOfCollection": $relationship = "isMemberOfCollection"; $namespaceURI = 'info:fedora/fedora-system:def/relations-external#'; break; case "fedora:isPartOf": $relationship = "isPartOf"; $namespaceURI = 'info:fedora/fedora-system:def/relations-external#'; break; } if (substr($object, 0, 12) != 'info:fedora/') { $object = "info:fedora/{$object}"; } $relsextxml = new DomDocument(); $relsextxml->loadXML($relsext); $modified = FALSE; $rels = $relsextxml->getElementsByTagNameNS($namespaceURI, $relationship); if (!empty($rels)) { foreach ($rels as $rel) { if ($rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) { $rel->parentNode->removeChild($rel); $modified = TRUE; } } } if ($modified) { $this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml'); } return $modified; //print ($description->dump_node()); }
function import($xmlString, $type, $user, $group_e, $group_v, $mds, $langs, $lang_main, $params = false, $updateType = "", $md_rec = "", $fc = "", $public = 0) { /*--------------------------------------------------------------------- Import jednoho XML dokumentu $xmlString obsah xml souboru $format format souboru () $user prihlaseny uzivatel $group_e skupina pro editaci $group_v skupina pro prohlizeni $mds standard metadat $langs seznam pouzitych jazyku $public zda bude zaznam verejny ---------------------------------------------------------------------*/ $mod = 'all'; // mod pro import, all importuje vse, neco jineho preskakuji uuid $id = "1"; // identifikator DS - pouze jedna $rs = -1; //--------------------------------------------------------------------- $xp = new XsltProcessor(); $xml = new DomDocument(); $xsl = new DomDocument(); $OK = false; $esri = FALSE; if (!$xml->loadXML($xmlString)) { die('Bad xml format'); } //--- import kote etc (19139) if (!$OK) { $root = $xml->getElementsByTagNameNS("http://www.isotc211.org/2005/gmd", "MD_Metadata"); if ($root->item(0)) { /*$isValid = $xml->schemaValidate("http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/gmd/gmd.xsd"); if(!$isValid){ echo "WARNING! Imported XML file is not valid."; var_dump(libxml_get_errors()); }*/ $xslName = PHPINC_DIR . "/xsl/" . $this->xsl_files["iso"]; $OK = true; } } //--- import kote etc (19139) - ISO 19115-2 if (!$OK) { $root = $xml->getElementsByTagNameNS("http://www.isotc211.org/2005/gmi", "MI_Metadata"); if ($root->item(0)) { /*$isValid = $xml->schemaValidate("http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/gmd/gmd.xsd"); if(!$isValid){ echo "WARNING! Imported XML file is not valid."; var_dump(libxml_get_errors()); }*/ $xslName = PHPINC_DIR . "/xsl/" . $this->xsl_files["iso"]; $OK = true; } } //--- import nativni if (!$OK) { $root = $xml->getElementsByTagName("results"); if ($root->item(0)) { $featureCatalogue = $xml->getElementsByTagName("featureCatalogue"); if ($featureCatalogue) { $fc = strval($featureCatalogue->item(0)->getAttribute('uuid')); } $xslName = PHPINC_DIR . "/xsl/" . $this->xsl_files["native"]; $OK = true; } } //--- kontrola, zda je ESRI if (!$OK) { $root = $xml->getElementsByTagName("Esri"); if ($root->item(0)) { if ($fc != '') { $xslName = PHPINC_DIR . "/xsl/esri2fc.xsl"; $lang_fc = $langs; } else { $xslName = PHPINC_DIR . "/xsl/" . $this->xsl_files["esri"]; } $OK = true; $esri = true; } } //--- import ISVS/MIDAS if (!$OK) { $root = $xml->getElementsByTagName("METAIS"); if ($root->item(0)) { $xslName = PHPINC_DIR . "/xsl/" . $this->xsl_files["isvs"]; $OK = true; } } //--- import WMC if (!$OK) { $root = $xml->getElementsByTagNameNS("http://www.opengis.net/context", "ViewContext"); if ($root->item(0)) { $xslName = PHPINC_DIR . "/xsl/" . $this->xsl_files["wmc"]; $OK = true; } } //--- zde pribudou dalsi typy pro import if (!$OK) { $rs = array(); $rs[0]['ok'] = 0; $rs[0]['report'] = "Bad metadata document format!"; return $rs; } $md = $this->xml2array($xml, $xslName); $lang = $md['MD_Metadata'][0]["language"][0]["LanguageCode"][0]['@']; if ($lang == 'fra') { $lang = "fre"; } // kvuli 1GE if ($lang == '' && $lang_main != '') { $lang = $lang_main; } $md['MD_Metadata'][0]["language"][0]["LanguageCode"][0]['@'] = $lang; if (strpos($langs, $lang) === false && $lang != '') { $langs = $lang . "|" . $langs; } // kontrola, zda je jazyk zaznamu v seznamu pouzitych jazyku if ($params) { $md = $this->array_replace_recursive($md, $params); } if ($fc != '') { $updateType = 'fc|' . $fc; } else { $uuid = $md['MD_Metadata'][0]['fileIdentifier'][0]['@']; // import obrazku z ESRI dokumentu if ($esri) { if ($this->extractImage($xml, "graphics/{$uuid}.png")) { if ($ser) { $pom = 'SV_ServiceIdentification'; } else { $pom = 'MD_DataIdentification'; } $md['MD_Metadata'][0]['identificationInfo'][0][$pom][0]['graphicOverview'][0]['MD_BrowseGraphic'][0]['fileName'][0] = "http://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['PHP_SELF']) . "/graphics/{$uuid}.png"; $md['MD_Metadata'][0]['identificationInfo'][0][$pom][0]['graphicOverview'][0]['MD_BrowseGraphic'][0]['fileDescription'][0] = "náhled"; } } } if ($md_rec != '') { $updateType = 'update|' . $md_rec; } // ulozeni dat $c = new MdImport(); $c->setTableMode($this->table_mode); $c->mds = $mds; if ($group_e) { $c->group_e = $group_e; } if ($group_v) { $c->group_v = $group_v; } //$c->setReportValidType('htmlsmall', false); // formát validace $c->setDataType($public); // nastavení veřejného záznamu $c->lang = $lang; // pokud není v datech, použije se toto nastavení jazyka //$c->stop_error = true; // pokud dojde k chybě při importu nepokračuje $c->stop_error = false; // pokud dojde k chybě při importu pokračuje $rs = $c->dataToMd($md, $updateType); //var_dump($rs); return $rs; }