예제 #1
0
 public static function buildDocument($path, $xpath = true, array $ns = array())
 {
     $ns[] = array("prefix" => "i", "uri" => "http://www.appflower.com/schema/");
     $document = new DOMDocument();
     $document->load($path);
     if ($xpath) {
         $xp = new DOMXPath($document);
         foreach ($ns as $data) {
             if (!$xp->registerNamespace($data["prefix"], $data["uri"])) {
                 throw XmlParserException("Unable to register namespace: " . $data["uri"]);
             }
         }
         return $xp;
     } else {
         return $document;
     }
 }
 public function getNew($type, $name = null)
 {
     try {
         if ($type == "elem") {
             return $this->document->createElementNS($this->namespace, $name);
         } else {
             if ($type == "doc") {
                 return new DOMDocument();
             } else {
                 if ($type == "attr") {
                     return new DOMAttribute($name);
                 } else {
                     throw XmlParserException("Bad input parameter for type..");
                 }
             }
         }
     } catch (Exception $e) {
         throw $e;
     }
 }