I was wondering if it is better/proper to reference the entities using a fragment identifier format - basically by inserting a hash before the name
[url] + # + [name] => http://example.com/page/#webPage
EDIT:
Following a kind answer from the ever-generous and great #Unor, I have added this edit to try confine the scope of my query and clarify the main issue I am getting at. I have also deleted most of the original question (about 95%) which (in hindsight) I feel detracts from:
1. my core question; and
2. the benefit to future readers.
Here is my issue in short:
Is the practice of manually typing in a hash at the start of microdata's itemid and json-ld's #id values valid?
Here is my issue expressed in more detail:
Can I insert a HASH symbol (#) into microdata's itemid values and json-ld's #id values, to create valid resulting URIs with a proper and valid use of a fragment identifier?
So if this is on a web page:
<div itemscope itemtype="http://www.schema.org/Person" itemid="#joe"></div>
Or if this is also on the web page:
{"#context":"http://schema.org",
"#type":"Person",
"#id":"#Joe"}
I understand they will be read to make a uri like this (assuming relative construction by the consumer as Google's structured data tester tool does):
http://www.example.com/page#joe
Is that uri:
a valid uri; and
is it properly using a fragment identifier (HASH)?
It’s a good practice to allow to retrieve a description about the entity when requesting the URI (see Cool URIs for the Semantic Web: 1. Be on the Web.).
By using Hash URIs, you get this functionality for free:
http://example.com/flower represents the document about a flower
http://example.com/flower#this represents the flower
→ When retrieving http://example.com/flower#this, you get the document about it
By using Slash URIs, you have to implement a redirect (with status code 303) yourself:
http://example.com/flower represents the document about a flower
http://example.com/flower/this represents the flower
→ When retrieving http://example.com/flower/this, you get 303-redirected to the URI about it (see an example)
So without knowing more about your backend, I’d suggest to go with Hash URIs, because it is typically easier to set up.
(I’m not sure what exactly you mean with "webpage entity", but just to make sure: the Hash URI should be for the "real-world object", not for the document.)
Edit (for your updated question):
Yes, you can provide the Hash URI in itemid and #id (example) by specifying only the fragment component (starting with a #).
So on a document with the URL http://example.com/foobar, these four statements generate the same Hash URI (http://example.com/foobar#this):
<article itemscope itemtype="http://voc.example.net/Example" itemid="#this">
</article>
<article itemscope itemtype="http://voc.example.net/Example" itemid="http://example.com/foobar#this">
</article>
<script type="application/ld+json">
{
"#context": "http://voc.example.net/",
"#type": "Example",
"#id": "#this"
}
</script>
<script type="application/ld+json">
{
"#context": "http://voc.example.net/",
"#type": "Example",
"#id": "http://example.com/foobar#this"
}
</script>
(And yes, your example URI is valid; here’s which characters the fragment component may contain.)
Notes:
The fragment is case-sensitive, so your itemid="#joe" and "#id":"#Joe" resolve to different URIs (j vs. J).
When not specifying an absolute Hash URI, you have to make sure that the URL of the current document is canonical. For example, the trailing slash matters (/page/#joe vs. /page#joe); the query component matters (the page /page?foo=bar would create the Hash URI /page?foo=bar#joe, not /page#joe); if the host has www. or not matters; the URI scheme matters (http vs. https); etc.
Related
I'm new to Dojo and i18n for that matter. I am looking to convert a couple of works to different languages in my app. I've read through a few articles and to be honest, I feel like a LOT of information is thrown at me to digest, and I'm struggling with it. Would someone be able to provide me with the simplest way I can possibly do this? Let's say I want to change the word 'Hello'. In my head it would be something like:
Dojo library ready for use
I define String 'hello' in my javascript file. It has the placeholder text of "hello"
I specify in my HTML that I want my page to be
"string specified here to display hello in a different language"
So that's as much as I can assimilate from my limited knowledge. How do I essentially get that sort of setup to work? I assume I need to require i18n on my page, but exactly how I execute this is still to be determined.
Any help would be super. Please bear in mind that I have a limited knowledge with your answer if at all possible, thanks!
The nls folder is normally used to store your translation strings and is usually a subdirectory next to the widget using it.
ie. If your widget is stored in myWidget.js within a folder called app, then your translation strings for myWidget.js are stored in a file with the same name (myWidget.js) in the directory app/nls.
This is just convention but is probably worth following as it makes your directory structure logical.
Here is an example of the myWidget.js widget:
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dojo/i18n!./nls/myWidget"
], function(
declare, _widget, _templated, strings, domAttr
){
"use strict";
var construct = declare([_widget, _templated], {
"i18n": strings,
"templateString": "<div>${i18n.hello}</div>"
});
return construct;
});
This is a very simple widget that creates a <div> (see templateString property) on the screen. The <div> should contain the text loaded from the translation file and assigned to the hello property.
The widget will need nls directory creating in the same directory as myWidget.js. In the nls directory you create another javascript file called myWidget.js (ie. same name as the parent). This file is you root translation file and looks like this:
define({
root: ({
"hello": "Hello"
})
});
Here you have assigned the string, "Hello" to the property hello. This is not very useful as no translations have been supplied. If you wanted to have a Norwegian translation then you would modify it like this:
define({
root: ({
"hello": "Hello"
}) ,
"no": true
});
Here you are saying that as well as the root translation strings you also have a Norwegian translation. You will then need to create your Norwegian translation file and place it in a subdirectory of nls called no. So you create another file called myWidget.js and place it in nls/no:
define({
"hello": "Hei"
});
The format for the translation file is slightly different to the root file. The default strings are used, unless a translation is available for the given string in the current browser language (ie. you do not need to translate every string, just the ones you want translating).
See the Dojo tutorial for internationalization for more help on this subject.
See sample project for the above code on Bitbucket
Loading translation-strings outside of widget:
The above examples show how to load translation text for a widget following the normal conventions. You can load any set of strings you want in any widget or any require statement. The dojo/i18n class is able to load any set of strings you specify.
eg:
require([
"dojo/i18n!<PATH TO TRANSLATION ROOT FILE YOU WANT TO LOAD>"
], function(string) {
// translation-string are stored in the 'strings' variable for the
// current browser language
});
OK, I've been looking through a representative sample of the MVC 3 routing questions/answers, and I answered 80% of my question. A good thing, but now the most difficult part remains unsolved.
In my world, I have a URL localhost/Location/Guid
Works great, based off of this route that I've entered before my default route:
routes.MapRoute(
"Location",
"Location/{id}",
new { controller = "Location", action = "Details", id = System.Guid.Empty }
);
I can pass in the Guid for the location I want displayed, but that's down-right FUGLY. I'd really like to see the URL displayed in the address bar, and linked within a page as: localhost/Location/Paris
Obviously, I could change the parameter to a string and pass in "Paris", but I don't understand how to get the database to understand that I want Paris, France and not Paris, Texas without the use of the Guid.
I really need some help on this one, not just to solve my immediate problem, but also to better understand routing in general. I thought I had a handle on it sufficient for my needs, but obviously, I don't.
Thanks in advance!
You're going to have to put something in the URL to disambiguate between Paris, France, and Paris, TX.
You could set up your route pattern to be `/Location/{country}/{region}/{city}', or you could slugify every possible location in your application
Use those location slugs: /Location/{locationSlug}. If you have multiple locations named "Paris", you slugify them and append an auto-incrementing # to the end (e.g., /Location/paris, /Location/paris-1, /Location/paris-2). Or you can add region/city/country info to the slug to disambiguate, instead of the #.
Do it stack overflow question style, where you have an ID, and then the location slug. It looks prettier and more concise if you are able to convert or map your GUID's to integers, so your pattern would be like this: Location/{id}/{locationSlug} (e.g., /Location/1245/paris).
I am trying to create an email link using MVC3 and strongly typed modeling. I want the subject of the email to contain the # sign similar to:
Request #56
My initial attempt looked like:
#Model.Name
It resulted in what I thought was perfect HTML:
John Stone
I found out that Internet Explorer does not like the # sign in the subject. If I clicked on the above "link", the subject would be set to:
Request
After searching here, I found that I needed to use %23 in place of the #. So my second attempt looked like:
#Model.Name
This resulted in the following:
Request # 56
Close but I do not want the space between the # and the number.
How do I properly use the # key without a space?
I am using MVC3 and trying to get this to work in IE8.
*added some details about the first attempt resulting html and how IE handles the subject
SOLUTION
There are actually two issues going on.
The first is IE will not allow the # in the subject text. So any instance of the # needs to be replaced with %23.
The second is the MVC3 parser does NOT handle #23#Model.ID correctly. It will NOT substitue in the value of Model.ID.
The correct solution is noted below but to "cut and paste":
#{
string requestValue = "%23" + Model.ID.ToString()
}
#Model.Name
The above will generate a properly clickable href mail link that would look like:
John Stone
When the above is clicked, the subject of the email will be "Request #5".
You can use an inline C# statement.
#{
string requestValue = "#" + Model.ID.ToString() // or "%23"
}
#Model.Name
I want to capture all search result links (search engine: http://search.yahoo.com) and summary from the result page. ClassName of Link is 'yschttl spt' and className for summary is 'abstr'
Source Code Looks like below for Link and summary.
Link:
<a id="yui_3_3_0_1_1301085039901361" dirtyhref="http://search.yahoo.com/r/_ylt=A0oG7m9u.4xNvWYA7N5XNyoA;_ylu=X3oDMTE2ZXNhNjRzBHNlYwNzcgRwb3MDMgRjb2xvA2FjMgR2dGlkA01TWUMwMDFfMTc5/SIG=11stois8r/EXP=1301106638/**http%3a//en.wikipedia.org/wiki/Pune,_India" class="yschttl spt" href="http://search.yahoo.com/r/_ylt=A0oG7m9u.4xNvWYA7N5XNyoA;_ylu=X3oDMTE2ZXNhNjRzBHNlYwNzcgRwb3MDMgRjb2xvA2FjMgR2dGlkA01TWUMwMDFfMTc5/SIG=11stois8r/EXP=1301106638/**http%3a//en.wikipedia.org/wiki/Pune,_India" data-bns="API" data-bk="5096.1"><b>Pune</b> - Wikipedia, the free encyclopedia</a>`
Summary Div:
<div id="yui_3_3_0_1_1301085039901338" class="abstr"><b id="yui_3_3_0_1_1301085039901337">Pune</b> is undoubtedly a great place to eat. Fergusson <b id="yui_3_3_0_1_1301085039901352">College</b> <b>Road</b> is full of budget eateries serving delicous hot food at nominal charges. For a range of multi-cuisine ...</div>
I am using below line of code to capture both (link and summary).
final List<WebElement> links = driver.findElements(By.className("yschttl spt"));
final List<WebElement> linksSummary = driver.findElements(By.className("abstr"));
But now working at all.
I also tried using below XPaths for Link:
//a[starts-with(#id, 'yui_')]
//a[#data-bns='API']
I cannot use ID as whole because that ID number is not same for all search result links.
Nothing is working. Please help.
thanks in advance.
The main problem is that you are not correctly asking for a classname. The instance of class="yschttl spt" says that the element may be identified by two class names, yschttl or spt. It does not say that the classname is yschttl spt so asking for By.className("yschttl spt") will always fail.
Note that the reason the XPath suggested by #Tarun works is that XPath has no notion of what an HTML class name is or should be. In XPath, #class simply specifies the name of an attribute--with no underlying semantics.
Further, note that a class name may not contain spaces. For more details about specifying class names, see the HTML class attribute specification.
I don't use selenium 2.0 but when I tried //a[#class='yschttl spt'] in Firefox XPath Checker, I got to see all 10 results in page. I am soon to begin with Selenium 2.0, may be I could try then...
Playing with the new(ish) url rewriting functionality for web forms, but I'm running into trouble trying to declare parameters as optional.
Here's the scenario. I've got a search function which accepts two parameters, sku and name. Ideally I'd like the URL for this search function to be /products/search/skuSearchString/nameSearchString. I also have various management pages that need to map to things like /products/management/ or /products/summary/. In other words, the last two parameters in the URL need to be optional - there might be one search string, or two, or none.
This is how I've declared my virtual URL:
Friend Const _VIRTUALURL As String = "products/{action}/{sku}/{*product}"
And added the following defaults:
Me.Defaults = New Web.Routing.RouteValueDictionary(New With {.sku = "/"})
Me.Defaults = New Web.Routing.RouteValueDictionary(New With {.product = "/"})
I have two problems with this setup. The most pressing is that the url seems to expect an sku parameter. So, /products/summary/ cannot be found but /products/summary/anyTextAtAll/ maps to the correct page. You get the same result whether the defaults are set to "/" or "". How do I ensure both sku and product parameters are optional?
The second is more a matter of interest. Ideally, I'd like the url to be able to tell whether or not it's got a product search string or a url search string. The obvious way to do this is to make one or the other default to a value I can just pick up and ignore, but is there a neater way of handling it?
I'm not sure I entirely understood the question, but I have some comments about what you've shown so far:
The manner in which you're setting defaults seems incorrect. You're first setting a default value dictionary with a value for "sku". You're then replacing the default value dictionary with a value for "product".
A default value of "/" is unlikely to be what you want. In this case it sounds like you want a default value of just "" (empty string).
Try something like:
Me.Defaults = New Web.Routing.RouteValueDictionary(New With {
.sku = "",
.product = "" })
My VB skills are rather weak, so the syntax I showed might not be exactly right.
I think that if you change both of these then you should be good to go.