I'm trying to output the following raw url in the view.
https://loopme.me/api/vast/ads?appId=e18c19fa43&vast=2&uid=1234&ip=8.8.8.8&bundleid=com.loopme&appname=my_talking_pet&sdk=16.2&exchange=admarvel
however, even if I wrap the dynamic content with #Html method, the output is always
https://loopme.me/api/vast/ads?appId=e18c19fa43&vast=2&uid=1234&ip=8.8.8.8&bundleid=com.loopme&appname=my_talking_pet&sdk=16.2&exchange=admarvel
that is to say, '&' is still escaped.
Can anyone help me to correctly output raw contents in the view? I'm using scala bases template engine.
code:
<vmap:VMAP xmlns:vmap="http://www.iab.net/videosuite/vmap" version="1.0">
#for(offset <- timeOffsets){
<vmap:AdBreak breakType="linear" breakId="#offset.id"
timeOffset="#timeOffset(offset)">
#for(campaign <- campaigns){
<vmap:AdSource allowMultipleAds="allowMultipleAds"
followRedirects="true" id="#campaign.id">
<AdTagURI templateType="vast3">
<![CDATA[
#Html(campaign.extTag)
]]>
</AdTagURI>
</vmap:AdSource>
}
<vmap:TrackingEvents>
<vmap:Tracking event="breakStart">
http://MyServer.com/breakstart.gif
</vmap:Tracking>
</vmap:TrackingEvents>
</vmap:AdBreak>
}
</vmap:VMAP>
In a HTML template
import play.twirl.api.HtmlFormat
HtmlFormat.raw(yourURL)
In a XML template
import play.twirl.api.XmlFormat
XmlFormat.raw(yourURL)
Related
I am using spark 2.3.2 with python 3.7 to parse xml.
In an xml file (sample), I have appended 2 xmls.
When I parse it with:
os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages com.databricks:spark-xml_2.11:0.7.0 pyspark-shell'
conf = pyspark.SparkConf()
sc = SparkSession.builder.config(conf=conf).getOrCreate()
spark = SQLContext(sc)
dfSample = (spark.read.format("xml").option("rowTag", "xocs:doc")
.load(r"sample.xml"))
I see 2 xmls' data:
However, what I need is to extract the info under "ref-info" tag (along with their corresponding key eids), so my code is:
(dfSample.
withColumn("metaExp", F.explode(F.array("xocs:meta"))).
withColumn("eid", F.col("metaExp.xocs:eid")).
select("eid","xocs:item").
withColumn("xocs:itemExp", F.explode(F.array("xocs:item"))).
withColumn("item", F.col("xocs:itemExp.item")).
withColumn("itemExp", F.explode(F.array("item"))).
withColumn("bibrecord", F.col("item.bibrecord")).
withColumn("bibrecordExp", F.explode(F.array("bibrecord"))).
withColumn("tail", F.col("bibrecord.tail")).
withColumn("tailExp", F.explode(F.array("tail"))).
withColumn("bibliography", F.col("tail.bibliography")).
withColumn("bibliographyExp", F.explode(F.array("bibliography"))).
withColumn("reference", F.col("bibliography.reference")).
withColumn("referenceExp", F.explode(F.array("reference"))).
withColumn("ref-infoExp", F.explode(F.col("reference.ref-info"))).
withColumn("authors", F.explode(F.col("ref-infoExp.ref-authors.author"))).
withColumn("py", (F.col("ref-infoExp.ref-publicationyear._first"))).
withColumn("so", (F.col("ref-infoExp.ref-sourcetitle"))).
withColumn("ti", (F.col("ref-infoExp.ref-title"))).
drop("xocs:item", "xocs:itemExp", "item", "itemExp", "bibrecord", "bibrecordExp", "tail", "tailExp", "bibliography",
"bibliographyExp", "reference", "referenceExp").show())
This extracts the info only from the xml with eid = 85082880163
When I delete this one and only kept the one with eid = 85082880158, it works.
My file is an xml file containing those 2 lines in the link. I have also tried to merge those 2 into one xml but could not manage.
What is wrong with my data/approach? (My ultimate plan is to create such a file containing thousands of different xmls to be parsed)
Your trouble lies in this piece of XML:
<xocs:item>
<item>
<bibrecord>
<head>
<abstracts>
<abstract original="y" xml:lang="eng">
<ce:para>
Apple is often affected by [...] intercellular CO <inf>2</inf> concentration [...]
^^^^^^^^^^^^
While it is correct XML (mixed content), this embedded tag <inf>2</inf> seems to be breaking spark-xml parser. If you remove it (or convert to corresponding HTML entities) you will get correct results.
I want to get html from markdown on Jupyter Notebook.
like this.
from IPython import display
display.Code("import this")._repr_html_()
But I get:
IPython.core.display.Markdown object has no attribute '_repr_html_'.
Any idea?
Here is an example of using the markdown package to convert markdown to HTML and combining it with other HTML
pip install markdown
import ipywidgets as widgets
import markdown
#Convert markdown to html
html = markdown.markdown("""# Pandas and Plotly guide
Here we have [Pandas](https://pandas.pydata.org/) and [Plotly Express library](https://plotly.com/python/plotly-express/) used in combination with:
* Ipyvuetify (ipywidgets Vuetify UI framework)
* Ipymonaco ( a text editor widget)
Available plot types:
""")
# copy some html from the plotly express website
html += """<ul>
<li><strong>Basics</strong>: <code>scatter</code>, <code>line</code>, <code>area</code>, <code>bar</code>, <code>funnel</code>, <code>timeline</code></li>
</ul>"""
help_links = widgets.HTML(value = html)
help_links
I don't think it is (directly) possible; the Markdown -> HTML conversion for, say, mdout = md("## string ..."); display(mdout) seems to happen in JavaScript, in the append_markdown function, defined here:
https://github.com/jupyter/notebook/blob/238828e/notebook/static/notebook/js/outputarea.js#L730
Of course, if someone can come up with a way, to do a JavaScript call from Jupyter Python cell to perform this conversion, and then get the results back in Python before doing the display(...), then it would be possible :)
For more discussion, see:
https://discourse.jupyter.org/t/how-to-obtain-html-string-from-markdown-as-jupyter-does-it/10589
EDIT: However, I just found a method to cheat through this (see also IPython: Adding Javascript scripts to IPython notebook) - you don't get the HTML string directly back in Python, but you can send the markdown string from Python, and control the display() of the converted string; the trick is to write in a separate <div>, and have JavaScript store the result of the conversion there.
So you can put this in a code (Python) cell in Jupyter:
def js_convert_md_html(instring_md):
js_convert = """
<div id="_my_special_div"></div>
<script>
//import * as markdown from "base/js/markdown"; //import declarations may only appear at top level of a module
//define(['base/js/markdown'], function ttttest(markdown) {{ // Mismatched anonymous define() module:
// console.log(markdown);
//}});
//const markdown = require('base/js/markdown'); // redeclaration of const markdown
//console.log(markdown); // is there!
function do_convert_md_html(instr) {{
//return instr.toUpperCase();
markdown.render(instr, {{
with_math: true,
clean_tables: true,
sanitize: true,
}}, function (err, html) {{
//console.log(html); //ok
$("#_my_special_div").html(html);
}});
}}
var myinputstring = '{0}';
do_convert_md_html(myinputstring);
</script>
""".format(instring_md)
return HTML(js_convert)
jsobj = js_convert_md_html("*hello* **world** $$x_2 = e^{x}$$")
display(jsobj)
This results with:
I have a UDF like this
case class bodyresults(text:String,code:String)
val bodyudf = udf{ (body: String) =>
//Appending body tag explicitly to the xml before parsing
val xmlElems = xml.XML.loadString(s"""<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE body [<!ENTITY nbsp " ">]><body>${body}</body>""")
// extract the code inside the req
val code = (xmlElems \\ "body" \\"code").text
val text = (xmlElems \\ "body").text.replace(s"${code}" ,"" )
bodyresults(text, code)
}
I am trying to do convert Body string into code, text strings
CODE: inside the xml elements named code.
TEXT: Everything else.
The column body type is String and the contents looks like this
<p>I want to use a track-bar to change a form's opacity.</p>
<p>This is my code:</p>
<pre><code>decimal trans = trackBar1.Value / 5000;
this.Opacity = trans;
</code></pre>
<p>When I build the application, it gives the following error:</p>
<blockquote>
<p>Cannot implicitly convert type 'decimal' to 'double'.</p>
</blockquote>
<p>I tried using <code>trans</code> and <code>double</code> but then the
control doesn't work. This code worked fine in a past VB.NET project. </p>
,While applying opacity to a form should we use a decimal or double value?
I am trying to use this UDF using the following command
val posts5=posts4.withColumn("codetext",bodyudf(col("Body")))
posts5.select("codetext").show()
This causes Error
org.apache.spark.SparkException: Failed to execute user defined function($anonfun$1: (string) => struct<text:string,code:string>)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 129; The element type "body" must be terminated by the matching end-tag "</body>"
But as you can see in the UDF I am appending body tag and closing it.
Note: Whats surprising is that it works fine if execute below command
posts5.select("codetext").show(19)
+--------------------+
| codetext|
+--------------------+
|[Given a represe...|
|[Is there any sta...|
|[What is the diff...|
|[How do I store b...|
|[If I have a trig...|
|[How do you page ...|
|[Does anyone know...|
|[Does anybody kno...|
|[What are some gu...|
|[There are severa...|
|[I wrote a window...|
|[How do I format ...|
|[One may not alwa... |
|[Are PHP variable...|
|[What's the simpl...|
|[Does anyone know...|
|[I'm looking for ...|
|[What is the corr...|
|[I was wondering ...|
+--------------------+
But if I use any number more than 19 its causing error
posts5.select("codetext").show(20)
or
posts5.select("codetext").show()
Just in case I am attaching the body string in the 20th row
<p>I have a Queue<T> object that I have initialised to a capacity of 2, but obviously that is just the capacity and it keeps expanding as I add items. Is there already an object that automatically dequeues an item when the limit is reached, or is the best solution to create my own inherited class?</p>,Limit size of Queue<T> in .NET?
I can not figure out what is the reason for this error. I can not find relevant information on web so please let me know whats causing error?
EDIT:
I dropped the row 20 because that string is missing the closing tag .
But now the error comes at row 19.
posts5.select("codetext").show(18) //18 or below works fine
posts5.select("codetext").show(19) // does not work
I have taken string in 19 th row passed it directly to function and its working fine.
But when I pass the entire column to UDF its not working?
Using the Kanna import I am currently parsing html using the following code:
if let doc = Kanna.HTML(url: NSURL(string: "https://en.wikipedia.org/wiki/Data")!, encoding: NSUTF8StringEncoding) {
// Search for nodes by XPath
for link in doc.xpath("/html/head...") {
primaryDisplay.text!=link.text!
print(link.text)
}
}
}
I was wondering how to identify specific "nodes"(not sure if that is the correct term) in/on a html page to parse the specific data I want...
Here is a image that shows what it is I wanted to know... I think...
A simple way to do what are you finding is using SwiftSoup
Try this:
do{
let html = "<!DOCTYPE html>" +
"<html>" +
"<head>" +
"<title>Some webpage</title>" +
"</head>" +
"<body>" +
"<p class='normal'>This is the first paragraph.</p>" +
"<p class='special'><b>this is in bold</b></p>" +
"</body>" +
"</html>";
let doc: Document = try SwiftSoup.parse(html)
let els: Elements = try doc.getElementsByClass("special")
let special: Element? = els.first()//get first element
print(try special?.text())//"this is in bold"
print(special?.tagName())//"p"
print(special?.child(0).tag().getName())//"b"
}catch Exception.Error(let type, let message)
{
print("")
}catch{
print("")
}
You should also take a look at xpath/xquery - it is a language specifically intended to traverse and query XML, which makes it applicable to XHTML and well HTML. XHTML is basically well formed HTML.
Assuming you had an xpath/xquery parser installed on your machine, you could...
get a list of all the p elements in the document: //p
get a list of all the p elements having class "special": //p[#class = 'special']
XQuery adds the ability to query documents using a SQL like syntax called FLWOR.
The difficulty in using this or any other parser for html is that often, the HTML is not well formed. That means that every opening tag does not have a closing tag. This makes any kind of parsing somewhat sketchy as the parser may not be able to figure out the hierarchy implied by the HTML.
I have:
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$this->render("voucher-list");
The problem is, when I execute:
$this->render("voucher-list");
It actually prints the information to screen. I want to return the data as an HTML string. This DOES NOT work:
$htmlcontent = $this->render("voucher-list");
How would I go about returning this information as a string?
If you want to send the data into JSON format then you need to make the array of data and use the following code to send the data:
$data = array(3,4,'test', 'my-name' => 3,4); //suppose this is your data
$this->_helper->viewRenderer->setNoRender(true);
$this->view->layout()->disableLayout();
echo Zend_Json::encode($data);
And you will get the data in JSON format.
See this: Zend Framework JSON Output