summaryrefslogtreecommitdiff
path: root/help3
diff options
context:
space:
mode:
authorOlivier Hallot <olivier.hallot@libreoffice.org>2020-01-05 10:34:25 -0300
committerOlivier Hallot <olivier.hallot@libreoffice.org>2020-01-05 14:49:11 +0100
commitb1173f6b3a6a14b4c439f9f478326bf48c8b6899 (patch)
treed7451c40801b8aed7f05c52310b5fa3e8157f77f /help3
parent08ee150ead33a9fd8fd6e8308420a2d05eb3e9f3 (diff)
Add XML formation check
Change-Id: I14d87d2e348a795286bd08d36015bac38c88a9ba Reviewed-on: https://gerrit.libreoffice.org/c/dev-tools/+/86242 Reviewed-by: Olivier Hallot <olivier.hallot@libreoffice.org> Tested-by: Olivier Hallot <olivier.hallot@libreoffice.org>
Diffstat (limited to 'help3')
-rw-r--r--help3/xhpeditor/index.php79
1 files changed, 44 insertions, 35 deletions
diff --git a/help3/xhpeditor/index.php b/help3/xhpeditor/index.php
index e01a172b..1ae2b341 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>';