Skip to content

Commit

Permalink
More fixes to "text" generation (not "html")
Browse files Browse the repository at this point in the history
  • Loading branch information
dand9959 committed Dec 13, 2017
1 parent afa2a55 commit aa8cb11
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions QRDAValidator/src/main/webapp/resources/scripts/displayXML.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var ignoreAnnotations = true; // ELM-specific Global variable controlling wheth
var loadingLib = false; // ELM-specific Global variables for loading library
var errorFlag = true;


function parseXMLString(xmlStr) {
var x, parser, xmlDoc, txt, etxt;
try {
Expand All @@ -29,6 +28,8 @@ function parseXMLString(xmlStr) {
txt = ""; //<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
level = 0;
txt += aggregateResults(txt, x);
// Now remove any blank/empty lines from the results (really only applies when ignoreAnnotations is true, and there are annotations.)
txt = txt.replace(/(^[ \t]*\n)/gm, "");
level = 0;
// Now show the parse error elements, if any.
if (xmlDoc.getElementsByTagName("parsererror").length > 0) {
Expand All @@ -50,20 +51,20 @@ function aggregateResults(textSoFar, thisNode) {
txt = "";
kids = thisNode.childNodes;
// If this node has no children, then just create the element with its attributes, and return
if (kids.length == 0) {
if (kids.length == 0 ) {
textSoFar += writeNewLine() + writeSpaces(level) + "<" + writeNodeName(thisNode.nodeName) + getNodeAttributes(thisNode) + "/>";
return textSoFar;
}
else {
// This node has children, so create the element with attributes, then recurse for each child node
textSoFar += writeNewLine() + writeSpaces(level) + "<" + writeNodeName(thisNode.nodeName) + getNodeAttributes(thisNode) + ">";
textSoFar += writeNewLine() + writeSpaces(level) + "<" + writeNodeName(thisNode.nodeName) + getNodeAttributes(thisNode) + ">";
for (i = 0; i < kids.length; i++) {
childNode = kids[i];

if (childNode.nodeType == 1) { // This node is an element node. Continue as long as its not a "parseerror" node
// This is ELM specific:
// Only process the node if either ignoreAnnotations = false OR if the node is not an annotation node
if (!ignoreAnnotations || (childNode.nodeName != "annotation" && childNode.nodeName != "a:s")) {
if (!skipNode(childNode)) {
if (childNode.nodeName != "parsererror") {
level++;
textSoFar = aggregateResults(textSoFar, childNode); // Recurse for this child
Expand All @@ -82,8 +83,11 @@ function aggregateResults(textSoFar, thisNode) {
textSoFar += childNode.nodeType + childNode.nodeValue;
} // end if not annotation
} // end for loop
textSoFar += writeNewLine() + writeSpaces(level) + "&lt;/" + writeNodeName(thisNode.nodeName) + ">";

var endTag = "</";
if (writeFormat=="html") {
endTag = "&lt;/"
}
textSoFar += writeNewLine() + writeSpaces(level) + endTag + writeNodeName(thisNode.nodeName) + ">";
}
return textSoFar;
}
Expand All @@ -108,9 +112,9 @@ function writeSpaces(x) {
var i, txt = "";
for (i = 0; i < x; i++) {
switch (writeFormat) {
case "text": txt += " "; break;
case "html": txt += "&nbsp;&nbsp;&nbsp; "; break;
default: txt += "&nbsp;&nbsp;&nbsp; "; break;
case "text": txt += " "; break;
case "html": txt += "&nbsp;&nbsp;&nbsp; "; break;
default: txt += "&nbsp;&nbsp;&nbsp; "; break;
}
}
return txt;
Expand All @@ -119,7 +123,7 @@ function writeSpaces(x) {
// Generate a newline character in text or html
function writeNewLine() {
switch(writeFormat) {
case "text": return "\n";
case "text": return "";
case "html": return "<br/>";
default: return "<br/>";
}
Expand Down Expand Up @@ -193,3 +197,12 @@ function writeComment(msg) {
}
}

function isAnnotation(node) {
// An annotation node for ELM is either named "annotation" or "a:s"
return (node.nodeName == "annotation" || node.nodeName == "a:s");
}

function skipNode(node) {
// If ignoreAnnotations is true and this node is an annotation, then skip it
return (ignoreAnnotations == true && isAnnotation(node) );
}
Binary file modified QRDAValidator/target/QRDA-Validator-distribution.zip
Binary file not shown.

0 comments on commit aa8cb11

Please sign in to comment.