Why do XML Namespaces usually start with http://...? - wpf

For example, the WPF namespace is:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
If I define my own namespace, should it also start with http? Isn't http misleading?

Namespaces doesn't have any meaning in their value, except for that value to be unique to avoid nameclashing. This is why you see a lot of companies putting in the URL for their own website as the namespace. URLs serve the same purpose, to be unique. Over the years it's just become good practice to use an URL, because if everyone does that, no nameclashing should occur :)

The W3C Document defining XML Namespaces says (quoting) :
Definition: An XML namespace is
identified by a URI reference
[RFC3986]
And RFC 3986 says (quoting) :
1.1.1. Generic Syntax
Each URI begins with a scheme name,
as defined in Section 3.1, that
refers to a specification for
assigning identifiers within that
scheme.
So I guess using http:// is what's closest to the standard -- as HTTP is the most common scheme used on the net.
In addition, as there can be only one owner for a domain name, it allows each company to use it's URL in its namespaces.

Another common way instead of using a URL starting with http:// is to use a Uniform Resource Name whose format is defined by RFC2141.
Such namespace identifiers are e.g. used by ODF (OpenDocument Format):
urn:oasis:names:tc:opendocument:xmlns:office:1.0
urn:oasis:names:tc:opendocument:xmlns:style:1.0
urn:oasis:names:tc:opendocument:xmlns:text:1.0

From this article at W3Schools:
"The namespace URI is not used by the parser to look up information. The purpose is to give the namespace a unique name. However, often companies use the namespace as a pointer to a web page containing namespace information. Try to go to http://www.w3.org/TR/html4/."

It is a reliable way to create a readable globally unique identifier. It may or may not be to a valid URL with more information.

Related

Using Reserved words as fields name

I am using external WSDL class for creating apex classes for my project, some of the classes have fields which name is reserved in apex, as limit word.
My problem here is, i can't call that field, sample example:
System.debug(object.limit);
where limit is field in object.
I can't even save the file because there is error in console saying:
Variable does not exist: limit
Any idea how reserved word in this cases can be escaped?
I've made an alternative version of Wsdl2Apex. You can get it for free from the FuseIT website.
In this alternative version it will add a _x suffix to the generated apex code for any reserved keywords that are encountered. The underlying generated SOAP request won't have this suffix.

Multiple phrases per language in cakephp

I am creating a website using CakePHP that requires translation not only into multiple languages but also multiple phrases per language depending on the type of the logged in user. This will allow the same functionality but with more formal or more friendly language without duplication.
As a very simple example:
Type 1: "Customer", "purchase","shopping cart"
Type 2: "Client", "buy", "basket"
Type 3: "User", "order","invoice"
Each of these types would be available in multiple languages.
I've got the standard localization working in CakePHP (one of the reasons I chose it!) and have the appropriate default.po files in the /Locale/[lang]/LC_MESSAGES/ directory and all is working fine there (thank you to the user who noted on this site that ger needed to be deu to work ;) ).
Before I get too far into the app I'd like to add the phrasing so I can set e.g. the language as French and phrasing as type2. If I was doing this outside of a framework I'd have a matrix look-up to find the correct string based on language and phrase keys but am unsure of how to do this within CakePHP's localization.
Currently I'm using the standard __([string]) convention but as this is early in the development cycle it would be trivial to change if necessary.
I was considering using __d([phrase],[string]) but can't see how to set this without creating my app as a plugin and then I'm back to the same problem with /Locale/
I have been unable to find any example of this in my searches on SO or the cakePHP community sites so would be grateful for any suggestions.
Is there a standard way to do this within cakePHP? if not, what would be a good "best practice" way to implement this?
Edit - following the answer below here's how it was implemented:
in /app/Locale/[lang]/LC_MESSAGES/ I created a new .po files with the new phrasing in them as phrase1.po, phrase2.po etc.
Where I set the language I also set the phrasing where the phrase file matches the name of the po file:
Configure::write('Config.language', 'deu');
Configure::write('App.langDomain', 'phrase1');
and all strings were wrapped with:
__d(Configure::read('App.langDomain', 'string')
And it just works.
Use __d() like this:
__d(Configure::read('App.langDomain'), 'Some string');
In bootstrap.php check the conditions and set App.langDomain based on whatever you need.
__d() has nothing to do with plugins, you can use it everywhere.
And alternative would be to wrap your translations with a custom method, something like
__dd(Configure::read('App.langDomain'), array('foo' => __('String1', 'bar' => __('String2'));
The array is an array of langDomain => stringForThatDomain mappings. Your __dd() method would take the one that is passed in the first argument.

Change NamespaceManager on Full Text Search GAE

We have an application in GAE, and we are reenginering this to use Full Text. We have to index all data already in the GAE and our application also use namespaces.
We are trying to create a java procedure to be runned by administrator, who has not namespace. In other services, we have created similar java procedures, applying namespace by code, so the idea is to index all data in each namespace. (We use NamespaceFilter to control user domain.)
This is part of code:
private static final Index INDEX = SearchServiceFactory.getSearchService()
.getIndex(IndexSpec.newBuilder().setName("Actividad"));
NamespaceManager.set("userdomain1");
INDEX.add(doc);
Setting namespace is ignored.
Is this the expected behaviour? Is there an alternative way to index all the information in every namespace?
With similar code on datastore it's work fine.
A SearchService object is bound to a namespace, so you need to call NamespaceManager.set() before calling SearchServiceFactory.getSearchService(). Alternatively, call the version of getSearchService() that has a namespace parameter. See:
https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/search/SearchServiceFactory#getSearchService(java.lang.String)

Qualified name in namespace declaration

After reading MSDN-XAML Namespaces and MSDN-Understanding XAML Namespaces, I still do not understand the purpose of having a Qualified Name (QName).
Take the following namespace declaration as an example:
xmlns:x='http://www.w3.org/1999/XSL/Transform'
x is the prefix short for the full URI (in this case, an URL) : http://www.w3.org/1999/XSL/Transform. Then there is this QName called xmlns. The definition for QName in mdsn is:
This complete name including the prefix is the lexical form of a
qualified name (QName):
What's that supposed to mean and why is it there since thet statement already has a locator and a prefix to identify the namespace and its names to be used?
I think more than this being an XAML question it is just an XML namespace question.
The xmlns attribute (a special attribute) is just the attribute used in XML to define a namespace. It says "here comes a namespace declaration". If you do not add a prefix, then you are telling it to set the namespace that is the value of the attribute as the default namespace for the page. If you omit in completely the default namespace is then assumed to be the value of the attribute (after the = and between the quotes).
XAML is XML and chooses to use the XML mechanism for declaring namespaces. I guess they could have created their own mechanism for doing it but since they didn't, if you added your namespace as you hint at in your question, without the xmlns:, the app processing the XML (the .NET framework in this case, parses the XAML file) would not know you were trying to define a namespace; it would think you were adding an attribute called "x" to the element it was defined in (which would most likely not be an attribute that is defined for that element).
For more about XML namespaces
http://www.w3.org/TR/REC-xml/
http://www.w3schools.com/XML/xml_namespaces.asp
http://en.wikipedia.org/wiki/XML_namespace

App Engine - why are there PhoneNumber, Link, Rating etc classes?

I haven't found any reason for the existence of a few of the App Engine classes. There's a PhoneNumber, a Link, a PostalAddress, a GeoPt, a Rating, etc. Why are these given special treatment? They don't seem to have any smarts - e.g. geo searching. I know Link has more space than a String property, but the rest?
See:
http://code.google.com/appengine/docs/java/datastore/dataclasses.html
Those types are 'semantic' types. They're present in the Java API for parity with the Python API. In the Python API, they define special behaviour with regards to the .to_xml() method - for example, a PhoneNumberProperty serializes like this:
<property name="foo" type="gd:phonenumber"><gd:phoneNumber>12345-678</gd:phoneNumber></property>
I think they're mostly just there to cover common cases and save developers time. If a lot of apps use a phone number field, why require each developer to have to write them? A developer can still write their own if they need/want to.
Not sure about java, but in python the following model/code (tested on dev server) will throw BadValueError, with the message "Invalid URL: stackoverflow.com"
class foo(db.model):
link = db.LinkProperty()
bar = foo()
bar.link = 'stackoverflow.com'
While:
bar.link = 'http://stackoverflow.com'
Works fine.
I haven't tested, but the other properties may or may not also do validation.
Basically using this types in your models allows to add indirect meta data to your code. This may be useful if you are working with any kind of universal renderer for your model classes or if you are performing validation of user input on your models.
For example if you are using PhoneNumber type for a field named userNumber you reflection based renderer may understand that it should automatically assign corresponding validator to text field which will represent it.
Regards,
Pavel.

Resources