Print javascript using R? - r

I would like to produce a text file so an engineer can run the java script. It has a header (top portion) that never changes like below (snippet).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
var myChart = new Chart.Bubble('myChartContainer', {
width: 500,
height: 500,
After this chunk will be my R analysis output. So far this is what I tried (very manual but doesn't work, regardless). I tried paste(), cat() too but it didn't work either.
print("<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"")
Is there any way to plant this chunk of code nicely in text file using R?

You can copy and paste the info. The only problem is escaping the special characters. So use readLines which will escape them for you.
headerInfo <- paste(readLines(file("clipboard")), collapse="\n")
cat(headerInfo)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>

You need to escape the quote marks so that R doesn't think that the string ends after PUBLIC.
The backslash \ is used to escape characters, E.g:
print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"")
And if your string has a backslash, you need to put two backslashes in the print function.

Related

Do I realy need this html-dtd folder for xhtml?

I asked myself, which function has a html-dtd folder with this files:
xhtml-lat1.ent
xhtml-special.ent
xhtml-symbol.ent
xhtml1-frameset.dtd
xhtml1-strict.dtd
xhtml1-transitional.dtd
I downloaded it from a German site, which recommend it when using xhtml.
Do I realy need it, if my head already looks like this?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Maybe somebody could also explain what these files actualy do.

What's the best way to add a CSS file to the XHTML page

Option 1 <?xml-stylesheet?>
<?xml-stylesheet href="style.css" type="text/css"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Title</title>
</head>
<body></body>
</html>
Option 2 <link/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Title</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body></body>
</html>
Both works. Just wondering which is better.
Thanks.
<link> is more cross-browser compatible. Having anything before the DOCTYPE declaration tends to lead to unexpected results, especially in older browsers.
Furthermore, <?xml-stylesheet?> is designed for XML. Unless you're sure your XHTML page is being served in XML mode you should avoid it anyway.
Second option is more comfortable to use still if you have to link more than one stylesheet then you would like to add <link> easily.

Why does £ turn to A using xhtml and css

I have noticed when i put a £ sign in it turns out to be a A when i look at my website in firefox. Do you know the reason why this is happening?
Thanks
it sounds like you've got a page encoded in UTF-8, but being displayed as Latin-1 - make sure the meta tags and/or server headers tell browser what encoding the page uses.
In an XHTML file, you need to declare the encoding in the initial XML tag, and for maximum compatibility, include a meta tag also
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
...
</head>
Bobince suggests in a comment that for maximum backwards compatibility you do something like this
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
...
</head>
If you're curious why you get strange letters, here's the likely explanation...
The pound sign is Unicode character U+00A3
This is encoded in UTF-8 as the two byte sequence C2 A3
if you interpreted that as Latin-1, you'd get ã

Full Example XHTML document showing how to define additional attributes

I am trying to extend an xhtml document to allow extra attributes.
In the w3.org it gives an example like so:
<!ATTLIST a
myattr CDATA #IMPLIED
>
See: 6.1. Defining additional attributes -
http://www.w3.org/TR/1999/xhtml-modularization-19990406/developing.html#s_dev_attrs
However i am not sure where to put that statement.
I have tried adding it like so:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<!ATTLIST a
myattr CDATA #IMPLIED
>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
</head>
<body>
...
</body>
But when I pick up the doc using DOM that extra DTD statement is ignored.
I have also tried:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!ATTLIST a
myattr CDATA #IMPLIED
>
]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
</head>
<body>
...
</body>
But that really caused DOM to throw a wobbly.
So I'd appreciate it if someone could show me a sample xhtml document that has an additional attribute defined. (i.e minimal full doc that could validate)
As you might have guessed....xhtml is not my strong point.
Your second example is correct, apart from the missing </html> end-tag. With that added it parses OK for me. What exactly “throws a wobbly”?
The ATTLIST declaration must indeed go in the DTD, the internal subset of which is within square brackets inside the DOCTYPE declaration.
(What are you hoping to achieve with this? Browsers don't care, even if they are running in native application/xhtml+xml mode. In normal text/html tag soup mode the DTD internal subset will just confuse them.)

DocType HTML Attribute

What is the purpose this and why this be added when we add new aspx page?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
What I have got behviour is, When I remove from page, the design look good and my modal popup is not working in IE only but working on Mozila, and when I add this design disturbed and modal popup working fine.
Thanks
the doctype tells the browser what sort of rendering mode to use when rendering the web page. this can have effects on CSS layouts and cross browser development. Eric Meyer has a good article explaining it indepth.
http://www.ericmeyeroncss.com/bonus/render-mode.html
The one you point out there makes the browser view the html as XHTML 1.0 the full list of doc types allowed is here;
http://www.w3.org/QA/2002/04/valid-dtd-list.html
Read
A valid HTML document declares what
version of HTML is used in the
document. The document type
declaration names the document type
definition (DTD) in use for the
document
HTML version information
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
The Transitional type is used when HTML presentational features are included in the document instead of in a style sheet. This is done to accomodate older browsers that don't support CSS.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The Frameset type is used in documents that have frames.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
The same three document types are also used in XHTML 1.0:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
Since the declaration is actually a comment tag, it won't confuse older browsers that don't understand the statement.

Resources