find redirect META in DOMDocument with DOMXPath - dom

I have the following HTML:
<html>
<head>
<meta http-equiv="refresh" content="0;URL=http://amazingjokes.com" />
</head>
</html>
I want to find the META with the redirect, so I wrote the following XPath query:
/html/head/meta[#http-equiv="refresh"]
However, the '-' in 'http-equiv' is causing an error:
Invalid regular expression: //html/head/meta[#http-equiv="refresh"]/:
Range out of order in character class
How can I properly rewrite the xpath query to be able to find the meta redirect?
I experimented with this, when I remove the '-' from the HTML code and the query things work as expected, but unfortunately the 'http-equiv' is a set standard, so I can not change that. This experiment showed me I am very close...

However, the '-' in 'http-equiv' is causing an error:
Invalid regular expression: //html/head/meta[#http-equiv="refresh"]/:
Range out of order in character class
Obviously, the XPath engine you are using is buggy.
The XPath expression used in the question is a valid XPath 1.0 expression and it selects the wanted <meta> element.
Here is an XSLT - based verification:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select="/html/head/meta[#http-equiv='refresh']"/>
</xsl:template>
</xsl:stylesheet>
When the transformation above is applied on the provided XML document:
<html>
<head>
<meta http-equiv="refresh" content="0;URL=http://amazingjokes.com" />
</head>
</html>
the XPath expression is evaluated and the selected in this evaluation node is output:
<meta http-equiv="refresh" content="0;URL=http://amazingjokes.com"/>

Related

How to include <meta charSet="utf-8" /> in react-testing-library?

I'm using jest-image-snapshot with react-testing-library so that I can run some visual regression tests. The issue I'm having is that I need to define <meta charSet="UTF-8" /> (otherwise my image-snapshots don't render correctly), however react-testing-library strips out all <html>, <head> and <body> tags.
If I wrap my component like so:
<html>
<head>
<meta charSet="utf-8" />
</head>
<body>
<ComponentToTest />
</body>
</html>
Then it ends up rendering as:
<DocumentFragment>
<meta charset="UTF-8" />
<ComponentToTest />
</DocumentFragment>
Which of course doesn't set the encoding to UTF-8 as it's not within <head>.
The result of this is that any components that include a unicode character will render with a weird character instead.
For example, using ​ (zero width space) will render as â€<. This results in my image-snapshots looking like this: https://i.imgur.com/fSK5gJ0.png
Is there any workaround here to define the character encoding?
EDIT: It seems I can change the container element (https://testing-library.com/docs/react-testing-library/api#container), but I can't define the container as { container: document.documentElement } as apparently it needs an .appendChild() to work. Is it possible to define the container element as the <html> itself? That would solve my issue if it's possible.

Displaying XML using google-code-prettify

I can't seem to get google prettify to work with basic XML: anyone got this to work, or can see what I am doing wrong: here is my code:
<html>
<head>
<meta charset="utf-8" />
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&skin=sunburst&lang=xml"></script>
</head>
<body>
<h1>XML Output</h1>
<pre class="prettyprint" id="quine" style="border:4px solid #88c">
<Rest_appt_pull licenseKey="123" passWord="456" start="30-oct-2014 00:00:00" finish="31-oct-2014 23:59:59" p_method="event">
<timings>
<entry label="Read"
time=".03"
segment=".03" />
<entry label="Processing XML"
time=".04"
segment=".01" />
</timings>
</Rest_appt_pull>
</pre>
</body>
</html>
Any help would be gratefully appreciated
The root cause is html tag symbol.
Change < to <
Change > to >
You need to html encode your xml code example first. You can use one of available online tools to do that. Then just wrap it in pre/code
<pre class="prettyprint lang-xml"> ... your html encoded xml code ... </pre>
and attach js code on the site.

<jsp:root and <html xmlns

In a JSP, do I need to provide a jsp:root directive and an XML namespace declaration. Or only the later. That is, if I have the following:
<jsp:directive.page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
/>
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:s="http://www.springframework.org/tags"
/>
<!DOCTYPE html>
<html xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:s="http://www.springframework.org/tags">
<head>
... remainder of my HTML page
should I remove the jsp:root element? The information seems redundant. Removing the namespace declaration from the html element makes Eclipse complain.
You need the jsp:root element to set up the rest of the document to understand tags beginning with s: or c:. So don't remove it.

How to use DITA subject scheme maps to produce facets for faceted search

I have a DITA topic map that contains a subject scheme map that defines a taxonomy.
The topics in my topic map have been tagged with values from the taxonomy.
How can I render my topic map with facets to allow retrival of the topics, where the facets are the values from the subject scheme map?
John.
DITA 1.2 gives you the means to create a taxonomy or facet hierarchy -- the subjectScheme map -- and the means to apply the taxonomy or facet hierarchy to your DITA content -- the classification map.
To take advantage of that markup and implement a faceted-browsing experience, you need two things:
A processor that uses the subject classification values as it renders the output
A viewing application that implements faceted browsing
Currently, I am not aware of any DITA processors or viewing applications that do this.
Well, unless I'm misunderstanding the question, I assume you mean rendering to XHTML and that you want the facet metadata in the output for use in retrieval there by the end user? And I guess you want it in a meta tag then.
If so, I would do it like this:
For the sake of the example, I will assume that you have made a taxonomy that maps to the #product attribute.
First, in the stylesheet dita2htmlImpl.xsl, find the following template and copy it to your custom.xsl to override it (as an alternative you could do another override the get-meta template in get-meta.xsl, but it's so long...), and add a call to generateProductMetadata:
<xsl:template match="*" mode="chapterHead">
<head><xsl:value-of select="$newline"/>
<!-- initial meta information -->
<xsl:call-template name="generateCharset"/> <!-- Set the character set to UTF-8 -->
<xsl:call-template name="generateDefaultCopyright"/> <!-- Generate a default copyright, if needed -->
<xsl:call-template name="generateDefaultMeta"/> <!-- Standard meta for security, robots, etc -->
<xsl:call-template name="getMeta"/> <!-- Process metadata from topic prolog -->
<xsl:call-template name="copyright"/> <!-- Generate copyright, if specified manually -->
<xsl:call-template name="generateCssLinks"/> <!-- Generate links to CSS files -->
<xsl:call-template name="generateChapterTitle"/> <!-- Generate the <title> element -->
<xsl:call-template name="gen-user-head" /> <!-- include user's XSL HEAD processing here -->
<xsl:call-template name="gen-user-scripts" /> <!-- include user's XSL javascripts here -->
<xsl:call-template name="gen-user-styles" /> <!-- include user's XSL style element and content here -->
<xsl:call-template name="processHDF"/> <!-- Add user HDF file, if specified -->
<xsl:call-template name="generateProductMetadata"/> <!-- Add Product metadata -->
</head>
<xsl:value-of select="$newline"/>
</xsl:template>
Then, again in your custom.xml, add the template you called:
<xsl:template name="generateProductMetadata">
<meta name="product" content="{#product}"/>
<xsl:value-of select="$newline"/>
</xsl:template>
This gives me the following result in a test run:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="copyright" content="(C) Copyright 2005"/>
<meta name="DC.rights.owner" content="(C) Copyright 2005"/>
<meta name="DC.Type" content="topic"/>
<meta name="DC.Title" content="Technical data"/>
<meta name="DC.Relation" scheme="URI" content="18014398553839499_Technical_description.html"/>
<meta name="DC.Creator" content="Administrator"/>
<meta name="DC.Contributor" content="Administrator"/>
<meta name="DC.Date.Created" content="2013-03-05T11:13:04"/>
<meta name="DC.Date.Modified" content="2012-12-17T11:11:02"/>
<meta name="class" content="InfoType04"/>
<meta name="wf-state" content="NotReleased"/>
<meta name="DC.Format" content="XHTML"/>
<meta name="DC.Identifier" content="topic18014398553854475"/>
<meta name="DC.Language" content="en"/>
<link rel="stylesheet" type="text/css" href="commonltr.css"/>
<title>Technical data</title>
<meta name="product" content="product1"/>
</head>
Is that what you're looking for?

HTML5 Valid Form Input/Fields

I'm a little confused as to what is considered valid markup for HTML5 input fields.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Site Name</title>
</head>
<body>
<form name="contact" method="post" action="/">
<p><input type="input" name="first_name" maxlength="255" /></p>
</form>
</body>
</html>
When I run this through the validator at w3.org I get the error Bad value input for attribute type on element input. with the /> highlighted in red. I look at the HTML-Tidy version it creates and it tells me to write it like this instead:
<p><input type="input" name="first_name" maxlength="255"></p>
But then when I validate that I then get the same error but with just the > highlighted in red. Then looking at the HTML-Tidy to see what it has corrected it to and it leaves is the same as if it's okay, but the error is still there. Is this considered valid HTML5 markup? Or is there a specific way of doing this?
type="input" is an invalid value of the attribute type of the input element.
This guide on the input element shows the allowed type attributes. Or check the HTML5 additional input types if you require one of those.
For a regular textfield you need to set the type attribute to type="text".
Input type "input" is not correct, you probably intented to use type="text".