예제 #1
0
 protected function import(DOMDocument $document, DomNode $node, array $statements)
 {
     /** @var Node $statement */
     foreach ($statements as $statement) {
         $newNode = $statement->getNode()->cloneNode(false);
         $newNode = $document->importNode($newNode);
         $newNode = $node->appendChild($newNode);
         if ($statement->hasChildren()) {
             $this->import($document, $newNode, $statement->getChildren());
         }
     }
 }
예제 #2
0
파일: wsf_wsdl_util.php 프로젝트: ztobs/wsf
/**
 * Recursive function to create schema from import schema
 * and also used to resove wsdl import problem
 * @param DomNode $parent parent dom node
 * @param DomNode $child dom node of import schema
 * @param DomDocument $doc DomDocument of parent DomNode
 */
function wsf_wsdl_append_node($parent, $child, $doc)
{
    if ($child == NULL) {
        return;
    }
    $imported_node = $doc->importNode($child, TRUE);
    if ($imported_node) {
        $parent->appendChild($imported_node);
    }
}
예제 #3
0
 /**
  *
  * @param DomNode $node
  * @param array $error
  */
 public function displayXmlError($node, $error)
 {
     $a = $this->errors->createAttribute("line");
     $t = $this->errors->createAttribute("code");
     $m = $this->errors->createTextNode(trim($error->message));
     $node->appendChild($a);
     $node->appendChild($t);
     $node->appendChild($m);
     $node->setAttribute("line", $error->line);
     switch ($error->level) {
         case LIBXML_ERR_WARNING:
             $node->setAttribute("code", $error->code);
             break;
         case LIBXML_ERR_ERROR:
             $node->setAttribute("code", $error->code);
             break;
         case LIBXML_ERR_FATAL:
             $node->setAttribute("code", $error->code);
             break;
     }
 }
예제 #4
0
/** create payload for arrays
 * @param $payload_dom - DomDocument for the payload building
 * @param $parent_node - The parent node to add the content
 * @param $user_arguments - The user given argument array 
 * @param $ns_prefix
 */
function wsf_create_payload_for_unknown_array(DomDocument $payload_dom, DomNode $parent_node, $user_arguments, $ns_prefix)
{
    if (is_array($user_arguments)) {
        foreach ($user_arguments as $key => $value) {
            if ($ns_prefix != NULL && !empty($ns_prefix)) {
                $node_name = $ns_prefix . ":" . $key;
            } else {
                $node_name = $key;
            }
            if (is_object($value)) {
                $current_node = $payload_dom->createElement($node_name);
                wsf_create_payload_for_unknown_class_map($payload_dom, $current_node, $value, $ns_prefix);
                $parent_node->appendChild($current_node);
            } else {
                if (wsf_is_map($value)) {
                    $current_node = $payload_dom->createElement($node_name);
                    wsf_create_payload_for_unknown_array($payload_dom, $current_node, $value, $ns_prefix);
                    $parent_node->appendChild($current_node);
                } else {
                    if (is_array($value)) {
                        foreach ($value as $child_value) {
                            if (is_object($child_value)) {
                                $current_node = $payload_dom->createElement($node_name);
                                wsf_create_payload_for_unknown_class_map($payload_dom, $current_node, $child_value, $ns_prefix);
                                $parent_node->appendChild($current_node);
                            } else {
                                if (wsf_is_map($child_value)) {
                                    $current_node = $payload_dom->createElement($node_name);
                                    wsf_create_payload_for_unknown_array($payload_dom, $current_node, $child_value, $ns_prefix);
                                    $parent_node->appendChild($current_node);
                                } else {
                                    if (is_array($child_value)) {
                                        error_log("Invalid array (inside an array) supplied around " . print_r($child_value, TRUE) . " \n");
                                    } else {
                                        $current_node = $payload_dom->createElement($node_name, $child_value);
                                        $parent_node->appendChild($current_node);
                                    }
                                }
                            }
                        }
                    } else {
                        $current_node = $payload_dom->createElement($node_name, $value);
                        $parent_node->appendChild($current_node);
                    }
                }
            }
        }
    } else {
        // just return the current value;
        $ele = $payload_dom->createTextNode($user_arguments);
        $parent_node->appendChild($ele);
    }
}
예제 #5
0
 /**
  * @param \DomDocument $dom
  * @param \DomNode $parent
  * @param string $identifier
  * @return void
  */
 protected function createXlfLanguageNode(\DomDocument $dom, \DomNode $parent, $identifier)
 {
     $labelNode = $dom->createElement('trans-unit');
     $idAttribute = $dom->createAttribute('id');
     $idAttribute->nodeValue = $identifier;
     $spaceAttribute = $dom->createAttribute('xml:space');
     $spaceAttribute->nodeValue = 'preserve';
     $sourceNode = $dom->createElement('source');
     $sourceNode->nodeValue = $identifier;
     $labelNode->appendChild($idAttribute);
     $labelNode->appendChild($spaceAttribute);
     $labelNode->appendChild($sourceNode);
     $parent->appendChild($labelNode);
 }
 /**
  * addArray recursive function 
  *
  * @param DomDocument $doc 
  * @param DomNode $n 
  * @param array $arr 
  * @param string $name 
  * @param string $debug 
  * @return void
  * @author Andy Bennett
  */
 public static function array_to_xml(&$doc, &$n, $arr, $name = "", $debug = 0)
 {
     if (count($arr) == 0) {
         return;
     }
     if (!is_array($arr) && !is_object($arr)) {
         return;
     }
     foreach ($arr as $key => $val) {
         if (is_int($key)) {
             if (strlen($name) > 1) {
                 $newKey = substr($name, 0, strlen($name) - 1);
             } else {
                 $newKey = "item";
             }
         } else {
             $newKey = $key;
         }
         $node = $doc->createElement($newKey);
         if (is_array($val) || is_object($val)) {
             $ak = is_object($arr) ? $arr->{$key} : $arr[$key];
             self::array_to_xml($doc, $node, $ak, $key, $debug);
         } else {
             $nodeText = $doc->createTextNode($val);
             $node->appendChild($nodeText);
         }
         $n->appendChild($node);
     }
 }
 /**
  * create a new element in the channels dom
  * @param DomNode $target
  * @param string $tag
  * @param array $attributes
  * @param string $content
  * @param bool $cdata
  * @return DomNode 
  */
 protected function createElementOn(&$target, $tag, $attributes = false, $content = false, $cdata = false)
 {
     $_tag = $this->dom->createElement($tag);
     if (is_array($attributes)) {
         foreach ($attributes as $key => $value) {
             $attr = $this->dom->createAttribute($key);
             $attr_val = $this->dom->createTextNode($value);
             $attr->appendChild($attr_val);
             $_tag->appendChild($attr);
         }
     }
     if ($content) {
         if ($cdata) {
             $content = $this->dom->createCDATASection($content);
         } else {
             $content = $this->dom->createTextNode($content);
         }
         $_tag->appendChild($content);
     }
     $target->appendChild($_tag);
     return $_tag;
 }
예제 #8
0
 /**
  * Append HTML as a child of this node
  * @param string $html The HTML to add, which is subsequently parsed into DOMNodes
  */
 function append_html($html)
 {
     $frag = $this->node->ownerDocument->createDocumentFragment();
     $frag->appendXML($html);
     $this->node->appendChild($frag);
 }