Create an Organization (How To)

@param cc_i_organization $org
@param DOMDocument $doc
@param object $xmlnode
@return DOMNode
503985
protected function create_organization(cc_i_organization &$org, DOMDocument &$doc, $xmlnode = null) {

        $usenew = is_object($xmlnode);
        $dnode  = $usenew ? $xmlnode : $doc->createElementNS($this->ccnamespaces['imscc'], "organization");
        $this->update_attribute($doc, 'identifier', $org->identifier, $dnode);
        $this->update_attribute($doc, 'structure', $org->structure, $dnode);

        $this->create_item_folder($org, $doc, $dnode);

        return $dnode;
    }
538899
protected function create_resource(cc_i_resource &$res, DOMDocument &$doc, $xmlnode=null) {
        $usenew = is_object($xmlnode);
        $dnode  = $usenew ? $xmlnode : $doc->createElementNS($this->ccnamespaces['imscc'], "resource");
        $this->update_attribute($doc, 'identifier', $res->identifier, $dnode);
        $this->update_attribute($doc, 'type', $res->type, $dnode);
        !is_null($res->href) ? $this->update_attribute($doc, 'href', $res->href, $dnode) : null;
        $this->update_attribute($doc, 'base', $res->base, $dnode);

        foreach ($res->files as $file) {
            $nd = $doc->createElementNS($this->ccnamespaces['imscc'], 'file');
            $ndatt = $doc->createAttribute('href');
            $ndatt->nodeValue = $file;
            $nd->appendChild($ndatt);
            $dnode->appendChild($nd);
        }
        $this->resources[$res->identifier]   = $res;
        $this->resources_ind[$res->files[0]] = $res->identifier;

        foreach ($res->dependency as $dependency) {
            $nd = $doc->createElementNS($this->ccnamespaces['imscc'], 'dependency');
            $ndatt = $doc->createAttribute('identifierref');
            $ndatt->nodeValue = $dependency;
            $nd->appendChild($ndatt);
            $dnode->appendChild($nd);
        }

        return $dnode;
    }
1292850
public function cloneNode(\DOMDocument $domDocument)
    {
        return $domDocument->importNode($this->getDomNode()->cloneNode(false), false);
    }
520010
protected function containerToDOM(\DomDocument $doc, \DomNode $node) : void
    {
        foreach ($this->children as $child) {
            $node->appendChild($child->toDOM($doc));
        }
    }
98589
public function toDoc(): \DOMDocument
    {
        if (null === $this->document) {
            throw new XslProcessorException(
                    'Can not transform, set document or xml file to transform first'
            );
        }

        $this->registerCallbacks();
        $result = $this->xsltProcessor->transformToDoc($this->document);
        if (false === $result) {
            throw new XslProcessorException($this->createMessage());
        }

        return $result;
    }
1168472
public function getOrganization($organization = '')
    {
        $contents = $this
            ->call('GET', self::ORGANIZATION_RESOURCE.'/'.$this->getOrganizationName($organization))
            ->getBody()
            ->getContents()
        ;

        return Organization::createFromJsonResponse($contents);
    }
1143374
public function deleteOrganization(Organization $org)
	{
        $url = self::makeUrl($org->id);
		$this->service->prepAndSend($url, array(204), 'DELETE', null, false);
	}
305280
public function getDocument($document, $rootNode)
	{
		$documentName = self::getName($document);
		$xpath = self::getXPath($document);

		if (!self::existsDocument($documentName))
		{
			throw new NotFoundException("Document " . $document . " doesn't exists in repository", 600);
		}

		$documentName = self::getFullFileName($documentName);
		
		if ($xpath == "")
		{
			$doc = XmlUtil::CreateXmlDocumentFromFile($documentName);
		}
		else
		{
			$doc = XmlUtil::CreateXmlDocumentFromStr("< $rootNode />", false);
			$source = XmlUtil::CreateXmlDocumentFromFile($documentName);
			
			$DocXpath = new DOMXPath($source);
			$nodes = $DocXpath->query($xpath);

			foreach ($nodes as $node)
			{
				$newNode = $doc->importNode($node);

				$doc->documentElement->appendChild($newNode);
			}

		}

		return $doc;
	}
691840
public function populateXmlDoc(&$doc, &$node, &$obj, $nested = false) {
    if ($this->has_changed()) {
      // If the name as changed so it's always output.
      $this->_unsavedKeys['name'] = true;

      $childNode = $node->appendChild($doc->createElement($this->getNodeName()));
      parent::populateXmlDoc($doc, $childNode, $obj, $nested);
    }
  }
280926
public static function addNodeFromFile(\DOMNode $rootNode, $filename, $nodetoadd)
    {
        if ($rootNode === null) {
            return;
        }
        if (!file_exists($filename)) {
            return;
        }

        $source = XmlUtil::createXmlDocumentFromFile($filename);

        $nodes = $source->getElementsByTagName($nodetoadd)->item(0)->childNodes;

        foreach ($nodes as $node) {
            $newNode = $rootNode->ownerDocument->importNode($node, true);
            $rootNode->appendChild($newNode);
        }
    }
336070
private function importXml(\DOMDocument $doc)
    {
        $importNodes=$doc->getElementsByTagName("import");
        for($i=$importNodes->length-1;$i>=0;$i--){
            $node = $importNodes->item($i);
            if($node->hasAttribute("file")){
                $file=$node->getAttribute("file");
                $path=rtrim(dirname($this->m_configFile),"/");
                $file=$path."/".ltrim($file,"/");
                if(file_exists($file)){
                    $_doc=new \DOMDocument();
                    $_doc->load($file);
                    $this->importXml($_doc);
                    $children=$_doc->documentElement->childNodes;
                    for($j=0;$j<$children->length;$j++){
                        $_node=$children->item($j);
                        if(is_a($_node,"DOMElement")){
                            $_node = $doc->importNode($_node, true);
                            $node->parentNode->insertBefore($_node,$node);
                        }
                    }
                    if(!in_array($file, $this->m_configFiles)){
                        $this->m_configFiles[]=$file;
                    }
                }
            }
            $node->parentNode->removeChild($node);
        }
    }
746044
public static function innerXML(\DOMNode $node, $xmlstring)
    {
        $xmlstring = str_replace("<br>", "<br/>", $xmlstring);
        $len = strlen($xmlstring);
        $endText = "";
        $close = strrpos($xmlstring, '>');
        if ($close !== false && $close < $len - 1) {
            $endText = substr($xmlstring, $close + 1);
            $xmlstring = substr($xmlstring, 0, $close + 1);
        }
        $open = strpos($xmlstring, '<');
        if ($open === false) {
            $node->nodeValue .= $xmlstring;
        } else {
            if ($open > 0) {
                $text = substr($xmlstring, 0, $open);
                $xmlstring = substr($xmlstring, $open);
                $node->nodeValue .= $text;
            }
            $dom = XmlUtil::getOwnerDocument($node);
            $xmlstring = "<rootxml>$xmlstring</rootxml>";
            $sxe = @simplexml_load_string($xmlstring);
            if ($sxe === false) {
                throw new XmlUtilException("Cannot load XML string.", 252);
            }
            $domSimpleXml = dom_import_simplexml($sxe);
            if (!$domSimpleXml) {
                throw new XmlUtilException("XML Parsing error.", 253);
            }
            $domSimpleXml = $dom->importNode($domSimpleXml, true);
            $childs = $domSimpleXml->childNodes->length;
            for ($i = 0; $i < $childs; $i++) {
                $node->appendChild($domSimpleXml->childNodes->item($i)->cloneNode(true));
            }
        }
        if (!empty($endText) && $endText != "") {
            $textNode = $dom->createTextNode($endText);
            $node->appendChild($textNode);
        }
        return $node->firstChild;
    }
229042
public function getOrganizationById($orgId)
    {
        $response = $this->doRequest(
            self::RESOURCE_GET_ORGANIZATION,
            [
                'orgId' => $orgId
            ]
        );

        return Organization::fromStream($response);
    }
391683
static public function build( XML_DOM_Node $tree, $encoding = "utf-8", $namespaces = array() )
	{
		$document	= new DOMDocument( "1.0", $encoding );
		$document->formatOutput = TRUE;
		$root		= $document->createElement( $tree->getNodename() );
		foreach( $namespaces as $prefix => $namespace )
			$root->setAttribute( "xmlns:".$prefix, $namespace );
		$root		= $document->appendChild( $root );
		self::buildRecursive( $document, $root, $tree, $encoding );
		return $document->saveXML();
	}
934891
public static function createFromSoapFault(\DOMDocument $document)
    {
        $response = null;
        $errorElement = $document->getElementsByTagNameNS(OrderService::NAMESPACE_SOAP, 'Fault');

        if ($errorElement->length > 0) {
            $response = new Error();

            $faultCode              = $document->getElementsByTagName('faultcode');
            $response->errorMessage = $document->getElementsByTagName('faultstring')->item(0)->nodeValue;

            switch ($faultCode->item(0)->nodeValue) {
                case self::SOAP_ERROR_SERVER:
                    $response->errorType = self::ERROR_TYPE_SERVER;

                    break;

                case self::SOAP_ERROR_CLIENT:
                    $response->errorType   = self::ERROR_TYPE_CLIENT;
                    $errorDetail = $document->getElementsByTagName('detail');

                    if (strpos($response->errorMessage, ':') !== false) {
                        $response->clientErrorType = substr($response->errorMessage, 0, strpos($response->errorMessage, ':'));
                    } else {
                        $response->clientErrorType = $response->errorMessage;
                    }

                    switch ($response->clientErrorType) {
                        case self::SOAP_CLIENT_ERROR_MERCHANT:
                            $response->clientErrorDetail = $errorDetail->item(0)->nodeValue;
                            break;

                        case self::SOAP_CLIENT_ERROR_PROCESSING:
                            $response->clientErrorDetail = $response->firstElementByTagNSString($document, OrderService::NAMESPACE_N3, 'ErrorMessage');;
                            break;

                        default:
                            throw new \Exception("Undefined SOAP Client Exception: " . $response->clientErrorType . ' (Complete SOAP Fault: ' . $document->saveXML() . ')');
                    }
                    break;

                default:
                    throw new \Exception("Undefined SOAP Error: (" . $document->saveXML() . ")");
            }
        }

        return $response;
    }
933927
public function import_resource(DOMElement &$node, cc_i_manifest &$doc) {

        $searchstr = "//imscc:manifest[@identifier='".$doc->manifestID().
                     "']/imscc:resources/imscc:resource";
        $this->identifier   = $this->get_attr_value($node, "identifier");
        $this->type         = $this->get_attr_value($node, "type");
        $this->href         = $this->get_attr_value($node, "href");
        $this->base         = $this->get_attr_value($node, "base");
        $this->persiststate = null;
        $nodo               = $doc->nodeList($searchstr."[@identifier='".
                              $this->identifier."']/metadata/@href");
        $this->metadata     = $nodo->nodeValue;
        $this->filename     = $this->href;
        $nlist              = $doc->nodeList($searchstr."[@identifier='".
                              $this->identifier."']/imscc:file/@href");
        $this->files        = array();
        foreach ($nlist as $file) {
            $this->files[]  = $file->nodeValue;
        }
        $nlist              = $doc->nodeList($searchstr."[@identifier='".
                              $this->identifier."']/imscc:dependency/@identifierref");
        $this->dependency   = array();
        foreach ($nlist as $dependency) {
            $this->dependency[]  = $dependency->nodeValue;
        }
        $this->isempty      = false;
    }
1019042
protected function createAccessDOMElement( DOMDocument $domDocument, eZContentObjectTreeNode $node )
    {
        $accessElement = $domDocument->createElement( 'AccessRights' );
        $accessElement->setAttribute( 'canRead', $node->attribute( 'can_read' ) ? '1' : '0' );
        $accessElement->setAttribute( 'canEdit', $node->attribute( 'can_edit' ) ? '1' : '0' );
        $accessElement->setAttribute( 'canCreate', $node->attribute( 'can_create' ) ? '1' : '0' );
        return $accessElement;
    }