Example #1
0
 /**
  * Computes the difference for two XML documents.
  *
  * @param string $basexml     Base document
  * @param string $comparedxml Compared document
  *
  * @throws Exception on error
  *
  * @return string Document with the computed difference
  *
  * @untranslatable //dm:delete/*
  * @untranslatable and
  */
 public function diff($basexml, $comparedxml)
 {
     $dom = new DOMDocument();
     $dom->loadXML(parent::diff($basexml, $comparedxml));
     $xpath = new DOMXPathExtended($dom);
     $deletes = $xpath->query("//dm:delete/*");
     foreach ($deletes as $node) {
         $query = "//" . $node->nodeName . "[";
         $firstattribute = true;
         foreach ($node->attributes as $attribute) {
             if ($firstattribute === false) {
                 $query .= " and ";
             }
             $query .= "@" . $attribute->nodeName . "=\"" . $attribute->nodeValue . "\"";
             $firstattribute = false;
         }
         $query .= "]";
         $document = new DOMDocument();
         $document->loadXML($basexml);
         $xpathdoc = new DOMXPathExtended($document);
         $list = $xpathdoc->query($query);
         foreach ($list as $originalnode) {
             $nodeimport = $dom->importNode($originalnode, true);
             $node->parentNode->replaceChild($nodeimport, $node);
         }
     }
     //end foreach
     $diff = $dom->saveXML();
     return $diff;
 }
 /**
  * @group slow
  * @dataProvider getTestFiles
  */
 public function testConversion($xml, $xsd, $class)
 {
     $serializer = self::$generator->buildSerializer(function (HandlerRegistryInterface $h) {
         $h->registerSubscribingHandler(new XmlSchemaDateHandler());
         $h->registerSubscribingHandler(new OTASchemaDateHandler());
         $h->registerSubscribingHandler(new BaseTypesHandler());
     });
     $original = $this->clearXML(file_get_contents($xml));
     $object = $serializer->deserialize($original, $class, 'xml');
     $new = $serializer->serialize($object, 'xml');
     $new = $this->clearXML($new);
     $differ = new \XMLDiff\Memory();
     $diff = $differ->diff($original, $new);
     $notEqual = strpos($diff, '<dm:copy count="1"/>') === false || strlen($diff) > 110;
     if (0 && $notEqual) {
         file_put_contents("a.xml", $original);
         file_put_contents("b.xml", $new);
         file_put_contents("c.xml", $diff);
         exit;
     }
     $this->assertFalse($notEqual);
 }
Example #3
0
 /**
  * @group long
  * @dataProvider getTestFiles
  */
 public function testConversion($xml, $xsd, $class)
 {
     $original = $this->clearXML(file_get_contents($xml));
     $object = self::$serializer->deserialize($original, $class, 'xml');
     $new = self::$serializer->serialize($object, 'xml');
     $new = $this->clearXML($new);
     $differ = new \XMLDiff\Memory();
     $diff = $differ->diff($original, $new);
     $notEqual = strpos($diff, '<dm:copy count="1"/>') === false || strlen($diff) > 110;
     if (0 && $notEqual) {
         file_put_contents("a.xml", $original);
         file_put_contents("b.xml", $new);
         file_put_contents("c.xml", $diff);
         exit;
     }
     $this->assertFalse($notEqual);
 }