Commit 92629e00 authored by Stephan Kreutzer's avatar Stephan Kreutzer

json_to_xml_2: Don't omit strings in arrays. Explicitly reflect strings as...

json_to_xml_2: Don't omit strings in arrays. Explicitly reflect strings as well as text literals in the XML output.
parent 2d100c07
......@@ -124,7 +124,7 @@ public class ParserJson
}
else if (node.getToken().equals("\"") == true)
{
this.writer.write("<object name=\"" + name.toString() + "\">");
this.writer.write("<string name=\"" + name.toString() + "\">");
String string = HandleString().toString();
// Ampersand needs to be the first, otherwise it would double-encode
......@@ -134,13 +134,13 @@ public class ParserJson
string = string.replaceAll(">", "&gt;");
this.writer.write(string);
this.writer.write("</object>");
this.writer.write("</string>");
}
else
{
this.writer.write("<object name=\"" + name.toString() + "\">");
this.writer.write("<literal name=\"" + name.toString() + "\">");
HandleText(node, JSON_TYPE.OBJECT);
this.writer.write("</object>");
this.writer.write("</literal>");
}
consumeWhitespace();
......@@ -193,11 +193,23 @@ public class ParserJson
}
else if (node.getToken().equals("\"") == true)
{
HandleString();
this.writer.write("<string>");
String string = HandleString().toString();
// Ampersand needs to be the first, otherwise it would double-encode
// other entities.
string = string.replaceAll("&", "&amp;");
string = string.replaceAll("<", "&lt;");
string = string.replaceAll(">", "&gt;");
this.writer.write(string);
this.writer.write("</string>");
}
else
{
this.writer.write("<literal>");
HandleText(node, JSON_TYPE.ARRAY);
this.writer.write("</literal>");
}
consumeWhitespace();
......@@ -230,7 +242,7 @@ public class ParserJson
if (node.getToken().equals("\"") == true)
{
return sb;
break;
}
else if (node.getToken().equals("\\") == true)
{
......@@ -241,6 +253,8 @@ public class ParserJson
sb.append(node.getToken());
}
}
return sb;
}
protected String HandleEscapeSequence()
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2018 Stephan Kreutzer
Copyright (C) 2018-2019 Stephan Kreutzer
This file is part of wordpress_retriever_1 workflow, a submodule of the
digital_publishing_workflow_tools package.
......@@ -29,8 +29,8 @@ along with wordpress_retriever_1 workflow. If not, see <http://www.gnu.org/licen
<xsl:template match="/array/object">
<wordpress-post>
<title><xsl:value-of select="./object[@name='title']/object[@name='rendered']//text()"/></title>
<content><xsl:value-of select="./object[@name='content']/object[@name='rendered']//text()"/></content>
<title><xsl:value-of select="./object[@name='title']/string[@name='rendered']//text()"/></title>
<content><xsl:value-of select="./object[@name='content']/string[@name='rendered']//text()"/></content>
</wordpress-post>
</xsl:template>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment