[Libreoffice-commits] dev-tools.git: help3/xhpeditor

Olivier Hallot (via logerrit) logerrit at kemper.freedesktop.org
Sun Jan 5 13:49:30 UTC 2020


 help3/xhpeditor/index.php |   79 +++++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 35 deletions(-)

New commits:
commit b1173f6b3a6a14b4c439f9f478326bf48c8b6899
Author:     Olivier Hallot <olivier.hallot at libreoffice.org>
AuthorDate: Sun Jan 5 10:34:25 2020 -0300
Commit:     Olivier Hallot <olivier.hallot at libreoffice.org>
CommitDate: Sun Jan 5 14:49:11 2020 +0100

    Add XML formation check
    
    Change-Id: I14d87d2e348a795286bd08d36015bac38c88a9ba
    Reviewed-on: https://gerrit.libreoffice.org/c/dev-tools/+/86242
    Reviewed-by: Olivier Hallot <olivier.hallot at libreoffice.org>
    Tested-by: Olivier Hallot <olivier.hallot at libreoffice.org>

diff --git a/help3/xhpeditor/index.php b/help3/xhpeditor/index.php
index e01a172..1ae2b34 100644
--- a/help3/xhpeditor/index.php
+++ b/help3/xhpeditor/index.php
@@ -75,50 +75,59 @@ $xhp = $_POST["xhpdoc"];
             echo '</div>';
         }elseif (isset($_POST["check_xhp"])) {
             libxml_use_internal_errors(true);
-            
+            libxml_clear_errors();
             $root = 'helpdocument';
-
             $old = new DOMDocument;
-            $old->loadXML($xhp);
-
-            $creator = new DOMImplementation;
-            $doctype = $creator->createDocumentType($root, null, 'xmlhelp.dtd');
-            $new = $creator->createDocument(null, null, $doctype);
-            $new->encoding = "utf-8";
-
-            $oldNode = $old->getElementsByTagName($root)->item(0);
-            $newNode = $new->importNode($oldNode, true);
-            $new->appendChild($newNode);
-
-            echo '<h2>Check XHP:</h2>';
-            if (!$new->validate()) {
-                echo '<p class="bug">This document does not verify the DTD and is NOT VALID!</p>';
+            
+            echo '<h2>XHP Verification</h2>';
+            if ( !$old->loadXML($xhp) ) {
                 $errors = libxml_get_errors();
+                echo '<p class="bug">The XML is malformed!</p>';
                 foreach ($errors as $error) {
-                    echo display_xml_error($error, explode("\n", $new->saveXML()));
+                    echo display_xml_error($error, explode("\n", $old->saveXML()));
                 }
                 libxml_clear_errors();
             }else{
-                echo '<p>This document verifies the DTD!</p>';
-            };
-            echo "<h2>Check duplicated Id's:</h2>";
-            $tags_id_uniq = array('paragraph','note','warning','tip','h1','h2','h3','h4','h5','h6');
-            $xmlarray = simplexml_load_string($xhp);
-            $i=0;
-            foreach($tags_id_uniq as $tag_uniq) {
-                foreach ($xmlarray->xpath("//$tag_uniq") as $tag){
-                    $idarray[$i] = $tag['id'];
-                    ++$i;
+                echo "<p>No XML errors found</p>";
+                $creator = new DOMImplementation;
+                $doctype = $creator->createDocumentType($root, null, 'xmlhelp.dtd');
+                $new = $creator->createDocument(null, null, $doctype);
+                $new->encoding = "utf-8";
+
+                $oldNode = $old->getElementsByTagName($root)->item(0);
+                $newNode = $new->importNode($oldNode, true);
+                $new->appendChild($newNode);
+
+                echo '<h2>Check XHP:</h2>';
+                if (!$new->validate()) {
+                    echo '<p class="bug">This document does not verify the DTD and is NOT VALID!</p>';
+                    $errors = libxml_get_errors();
+                    foreach ($errors as $error) {
+                        echo display_xml_error($error, explode("\n", $new->saveXML()));
+                    }
+                    libxml_clear_errors();
+                }else{
+                    echo '<p>This document verifies the DTD!</p>';
+                };
+                echo "<h2>Check duplicated Id's:</h2>";
+                $tags_id_uniq = array('paragraph','note','warning','tip','h1','h2','h3','h4','h5','h6');
+                $xmlarray = simplexml_load_string($xhp);
+                $i=0;
+                foreach($tags_id_uniq as $tag_uniq) {
+                    foreach ($xmlarray->xpath("//$tag_uniq") as $tag){
+                        $idarray[$i] = $tag['id'];
+                        ++$i;
+                    }
                 }
-            }
-            $dupped_array =  array_values(array_unique(array_diff_key($idarray, array_unique($idarray))));
-            if (count($dupped_array) > 0){
-                echo '<p class="bug">Found duplicated ids:</p>';
-                foreach($dupped_array as $dup) {
-                    echo "<p>$dup</p>";
+                $dupped_array =  array_values(array_unique(array_diff_key($idarray, array_unique($idarray))));
+                if (count($dupped_array) > 0){
+                    echo '<p class="bug">Found duplicated ids:</p>';
+                    foreach($dupped_array as $dup) {
+                        echo "<p>$dup</p>";
+                    }
+                }else{
+                    echo "<p>No duplicates ids found.</p>";
                 }
-            }else{
-                echo "<p>No duplicates ids found.</p>";
             }
         }elseif (isset($_POST["get_patch"])) {
         echo '<h2>Get Patch:</h2>';


More information about the Libreoffice-commits mailing list