HTML to org.w3c.dom.Document using Thymeleaf - html

I am currently using Thymeleaf to parse a HTML document and output it as a String which is then used to perform further operations.
I now need to pass Thymeleaf's output to a library which expects a org.w3c.dom.Document instead of a plain String, but I can't figure out how to do it without using another tool (I'd prefer not to do so).
Is there a way to make Thymeleaf output a org.w3c.dom.Document?

Related

How can I query JSON of an XML parsing in a client only app?

Sorry for the inappropriate question. But what do you recommend me to use to structure a library that can put a query arrangement on json formats generated by an XML parsing based on TEI p5? I tried to use GraphQL by converting the interfaces of my Angular application related to parsing information from XML to JSON in type to define a GraphQL schema but I don't think that's the way.
What I have to do is query, client only, some data encoded in XML (also wanting already parsed in JSON) and, for example, search for all occurrences of a specific data.
Do you have any roadmaps to recommend or some JSON query system that might be right for me?
You might take a look at https://www.npmjs.com/package/saxon-js. With SaxonJS you're able to run XPath expression against XML using JavaScript.

Convert JSON Plus JSON Schema into raw HTML?

I've found a lot of solutions that use on-the-fly scripting to convert JSON and JSON-Schema's to a human-readable form.
What I need, however, is a way to produce the raw HTML without any dynamic elements on the server side.
This form will need to be a read-only HTML view of the JSON object.
Options#1:
Take a JSON-Schema and convert it to a pure HTML template.
Store the pre-generated HTML Template.
Then, for each JSON I pass it and the template to a method (maybe w/ some css).
And finally get raw HTML.
Option#2:
Store the JSON-Schema.
Pass the JSON-Schema and the raw JSON to a method (maybe w/ some css).
And finally get raw HTML.

Using HTML Templates at server side

I am working on play framework with SCALA as backend.
Json data is given to the front end from the controller.
I want to add HTML as value of some fields of json.
This HTML will be kept as a template and data will be added in this template at run time.
I think i should put unique names in the HTML template and then these names will be replaced by the data which i want to add at run time. Ultimately, this HTML will be added in the json response.
Is my approach right? If not, what is the best approach to add data in an HTML template,add this template in json response and send this combined response to the front-end for further use?
Is it a good practice to use string replacement to add data in an HTML template?
I think as long as you use Play, you can put your HTML templates into app/views package. Let's say you call your template mytemplate.scala.html
You can parameterize this view as any Play view.
In the place in your code where you generate your JSON response you can then call mytemplate(parameters) to get html generated, Play will do all the work here for you. Then using play.api.libs.json.JSON object's methods and related facilities you can convert this html to JSON.
So in your controller's code you will have something like Ok(JSON.toJson(mytemplate(parameters)))
This is of course a sketch, so you will need to elaborate and try.

Render raw HTML from Razor view

I have a ASP.NET MVC4 controller function that returns dynamic html using a StringBuilder as a Json result.
This is an quality issue, because I don't want dynamic HTML being returned as a string property in a JSON result.
My goal is to make use of ASP.NET MVC to use .cshtml for example with a viewmodel so that I make an instance of the viewmodel, passing in the results and in the end, return the raw HTML of the view as a JSON result.
How can this be achieved ?
Instead of returning an HTML string inside of a JSON object, you may want to consider an action that returns a PartialView directly.
If you can't do this, because you need to return MULTIPLE html strings in one call, then I would advise taking a look at this thread which has a nice static method to turn a rendered view into a String: Render a view as a string.

HTML::Template Perl

IIs there a package similar to HTml::Template in perl which takes a JSON object and maps it to a HTML template file? I am building a web application using HTML::Template and will be receiving JSOn from a web services API, things will be made simple if I can templatize this JSOn to HTML instead of doing it the exact way HTML::Template requires.
HTML::Template just takes a data structure consisting of strings, hashes and arrays. JSON maps directly onto that.
$template->param(myData => JSON::Any->new->decode($json_string));
HTML::Template is a rather 'simple' templating engine - I am using quotes because its simplicity let's you do whatever you need in a view part from the Model View Controller architecture.
However, you can not execute arbitrary perl code inside a HTML::Template.
Also, due to the fact that in JSON you could have very complex data structures, I doubt that there are any suitable ways of using JSON in a straight way in your templates.
The only solution I see as possible is for you to use a Perl script that will parse the JSON, create some 'objects' and pass them to your templates. You already have that perl script - is the one that instantiate your HTML::Template object.
ok, a bit late, but:
HTML::Template always wants a hash of arrays of hashes and so on.
and you cannot navigate through the parameter stash.
If you want to do this, you might try out HTML::Template::Compiled which allows you to do this.
<tmpl_var some_hash.key.another_key[23] >
or with alternative delimiters:
[%= some_hash.key.another_key[23] %]
but note the documented differences of the module to HTML::Template.
So you decode your JSON string to a data structure and pass it to the template and then you can access all values somewhere deep in the structure.