Esempio n. 1
0
 public static function load($xmlfile)
 {
     if (is_file($xmlfile)) {
         $dom = new \DOMDocument();
         libxml_use_internal_errors(true);
         $dom->load($xmlfile);
         if ($dom->schemaValidate(__DIR__ . "/../Resources/xsd/star.xsd")) {
             $root = $dom->documentElement;
             //  Preliminary path modifications
             foreach ($root->getElementsByTagName("include") as $include) {
                 $include->nodeValue = FileUtils::resolveRelativePath(FileUtils::getFileParent($xmlfile), $include->nodeValue);
             }
             //  Reading attributes
             $actions = array();
             foreach (XMLUtils::getChildrenByName($root, "action") as $child) {
                 $actions[] = AbstractAction::parse($child);
             }
             $subsites = array();
             foreach (XMLUtils::getChildrenByName($root, "subsite") as $child) {
                 $subsites[] = Subsite::parse($child);
             }
             $targets = array();
             foreach (XMLUtils::getChildrenByName($root, "target") as $child) {
                 $targets[] = Target::parse($child);
             }
             return new Site($subsites, $targets, $actions);
         } else {
             //$errors = libxml_get_errors();
             throw new \Exception("Document validation failed for '" . $xmlfile . "'");
         }
     } else {
         throw new \Exception("Not a file '" . $xmlfile . "'");
     }
 }
Esempio n. 2
0
 public static function parse(\DOMNode $node)
 {
     if ($node->nodeName == self::getNodeName()) {
         $contexts = array();
         foreach (XMLUtils::getChildrenByName($node, Target::getNodeName()) as $child) {
             $contexts[] = Target::parse($child);
         }
         return new TargetList($contexts);
     }
     throw new \Exception("Unexpected node '" . $node->nodeName . "', expected '" . self::getNodeName() . "'");
 }
Esempio n. 3
-7
 public static function load($xmlfile, $prefix)
 {
     if (is_file($xmlfile)) {
         $dom = new DOMDocument();
         $dom->load($xmlfile);
         if ($dom->validate()) {
             $root = $dom->documentElement;
             //  Preliminary path modifications
             foreach ($root->getElementsByTagName("include") as $include) {
                 $include->nodeValue = FileUtils::resolveRelativePath(FileUtils::getFileParent($xmlfile), $include->nodeValue);
             }
             //  Reading attributes
             $actions = array();
             foreach (XMLUtils::getChildrenByName($root, "action") as $child) {
                 $actions[] = AbstractAction::parse($child);
             }
             $subsites = array();
             foreach (XMLUtils::getChildrenByName($root, "subsite") as $child) {
                 $subsites[] = Subsite::parse($child);
             }
             $targets = array();
             foreach (XMLUtils::getChildrenByName($root, "target") as $child) {
                 $targets[] = Target::parse($child);
             }
             return new Subsite($subsites, $targets, $actions, $prefix);
         } else {
             throw new Exception("Document validation failed for '" . $xmlfile . "'");
         }
     } else {
         throw new Exception("Not a file '" . $xmlfile . "'");
     }
 }