I am trying to find where the XSD and the semantics for the deployment descriptor web.xm file is defined in the Servlet 3.0 specification.
Alternatively, where is an authoritative description of the various supported elements and attributes that can appear inside web.xml and what the default behavior of the container is, in case some elements / attributes are absent.
This started by me wondering what is the default value for the http-only and secure elements inside session-config, e.g. as in:
<session-config>
<session-timeout>60</session-timeout>
<cookie-config>
<http-only>true</http-only>
<secure>false</secure>
</cookie-config>
</session-config>
I am reasonably certain the default values are false for both but I wanted to see where this is authoritatively specified.
Looking at the Java Servlet 3.0 spec there is no XSD. There is a sample XML file (on pg. 169) which has a schemaLocation attribute with value:
http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd
… which is broken. Googling for web-app_2_5.xsd an XSD file is found but it doesn't contain the definition of <session-config> element (I couldn't locate it even when googling for the other XSDs that that file imports).
The specification does contain graphical depictions of some elements (in the horrible late 90's style when such "visualizations" were in vogue) but this is all it contains for the session-config element:
There's no futher discussion for the cookie-config element.
I find it hard to believe that a specification does not contain the full XSD (or at least a link to it) and a detailed description of the semantics of all elements and attributes.
Am I missing something?
A list of schemas can be found at
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html
(at the very beginning it is stated "Latest Version: http://xmlns.jcp.org/xml/ns/javaee/", which in turn redirects to the link I've posted first; I think the latter URL should be used as a permalink)
Then you'll find the schemas grouped by Java EE version. I think servlet 3.0 is JEE 6, so:
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html#6
There you'll get the schemas:
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_0.xsd
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-common_3_0.xsd
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-fragment_3_0.xsd
Had problems with the schemas from oracle. The URLs were just not working, kept throwing an error.
so I switched to the jboss schema (at https://www.jboss.org/j2ee/schema/)
I replaced
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
with
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee https://www.jboss.org/j2ee/schema/web-app_2_4.xsd"
Also make sure the version attribute on the web-app tag is set correctly (e.g. version="2.4" in this case)
Related
I'm poking around in an App_Code.compiled file that was generated when i published my website. It looks something like:
<?xml version="1.0" encoding="utf-8"?>
<preserve resultType="6" virtualPath="/ProjectFolderName/App_Code/" hash="5b4133b" filehash="" flags="140000" assembly="App_Code" />
I'm wondering what the value for hash is used for?
The hash value is used to disambiguate the file name, so the page can be compared to past compilations and inspected for changes.
'hash' is used to check the current page for changes, whereas 'filehash' is used to check any source files the page depends on.
In Symfony 2's documentation regarding translations all of the XLIFF examples appear to use file.ext as the original file attribute. From XLIFF 1.2's documentation:
Original file - The original attribute specifies the name of the original file from which the contents of a element has
been extracted.
In Symfony 2's case I don't belief we're actually extracting any contents for translation, but the original attribute is required. The usage of file.ext is never explained in Symfony 2's documentation, whether it is simply a place holder and ignored, or whether it needs to point to an actual file. My best guess is that it is ignored by Symfony 2, but I haven't had a chance to do any tests or dig around in the code.
Second question: Would it be appropriate to specify a default set of translations, e.g. messages.default.yml and use this as the original file from which the XLIFF translations are derived?
XLIFF seems a little bit like overkill when it comes to translations for use with web applications...
Although original attribute of <file> is required in Xliff 1.2 spec and schema, you can ignore it and have a dummy string as its value so that your file passes schema validation.
One of the common uses of this property is when the strings from multiple documents (.properties files, gettext files, etc.) are extracted and reformatted as Xliff trans-units so that the strings from each individual file are placed under a respective individual <file> tag. original attribute can be used to keep the original filenames in an Xliff file with multiple <file> tags:
<?xml version="1.0" encoding="utf-8" ?>
<xliff version="1.1" xml:lang='en'>
<file source-language='en' target-language='de' datatype="plaintext" original="Sample.po">
...
<body>
<trans-unit id="1" restype="button" resname="IDC_TITLE">
<source>Title</source>
</trans-unit>
<trans-unit id="2" restype="label" resname="IDC_STATIC">
<source>&Path:</source>
</trans-unit>
...
</file>
<file source-language='en' target-language='de' datatype="plaintext" original="Sample.properties">
<trans-unit id="1" restype="label" resname="IDC_LABEL">
...
</body>
</file>
</xliff>
I agree that using Xliff for localizing small web applications can often be a bit of an overkill, but this format is arguably the only industry standard file format for localization data interchange at the moment. This makes it very popular with large scale localization implementation either simple source/target-structured files or heavily customized and tailored ones like those used in Translation Management Systems like SDL Idiom Worldserver.
Additionally, there is compatibility between Xliff and other standard file formats of OAXAL family.
I have a Resource in aSpring MVCapplication loaded from the classpath.
<bean id="myController" class="com.MyController">
<property name="myTemplate" value="classpath:myTemplate.txt"/>
</bean>
And I am trying to load it as a freemarker Template using this code:
private Resource myTemplate;
...
Configuration cfg = new Configuration();
cfg.setClassForTemplateLoading(this.getClass(), "/");
Template tpl = cfg.getTemplate(myResource.getFilename());
But I keep ending up in: java.io.FileNotFoundException: Template classpath:myTemplate.txt not found.
I tried implementing what wassuggested here however it doesn't seem to help.
The only hack I could findso far was to remove the "classpath: prefix from the filename String but I prefer not to do it
Any ideas...?
So what you are saying is that you don't want to remove "class:" from the template name, and according to this question you don't want to teach FreeMarker understanding it via a custom TemplateLoader either. I mean, if you bar these, what else could possibly solve this? I can only advice you to do the last; implement a custom TemplateLoader (either one that just removes the "class:" prefix then delegates to ClassTemplateLoader, or, even better, one that just delegates to a Spring ResourceLoader). That's how you configure FreeMarker to do what you want. It's not something extreme to do, implementing your own TemplateLoader.
Update: It might by useful to know that by default there's a mismatch between the FreeMarker template name syntax and Spring's resource name syntax. According the Spring syntax, you can write "classpath:foo.ftl" or "classpath:/foo.ftl". But FreeMarker assumes that the scheme part always ends with ://, and a lonely : or :/ is nothing special. So all these resource paths will be seen as relative paths, and so the current template directory will be prepended before them before the actual template resolution. To solve this, since FreeMarker 2.3.22, you can use Configuration.setTemplateNameFormat(TemplateNameFormat.DEFAULT_2_4_0) (template_name_format=DEFAULT_2_4_0 in Properties), which does consider : as scheme separator.
How do I solve the
Reference to undeclared namespace prefix: '%s'
problem with Microsoft's msxml implementation?
I'm using an XML feed from a government web-site that contains values i need to parse. The xml contains namespaces:
<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3c.org/1999/02/22-rdf-syntax-ns#rdf.xsd">
<item rdf:about="http://www.bankofcanada.ca/stats/rates_rss/STATIC_IEXE0101.xml">
<cb:statistics>
<cb:exchangeRate>
<cb:value decimals="4">1.0351</cb:value>
<cb:baseCurrency>CAD</cb:baseCurrency>
<cb:targetCurrency>USD</cb:targetCurrency>
<cb:rateType>Bank of Canada noon rate</cb:rateType>
<cb:observationPeriod frequency="daily">2011-05-09T12:15:00-04:00</cb:observationPeriod>
</cb:exchangeRate>
</cb:statistics>
</item>
</rdf:RDF>
Running the XPath query:
/rdf:RDF/item/cb:statistics/cb:exchangeRate/cb:targetCurrency
fails with the error:
Reference to undeclared namespace prefix: 'rdf'
Edit:
If i edit the original XML to remove all use of namespaces:
<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf>
<item>
<statistics>
<exchangeRate>
<value decimals="4">1.0351</value>
<baseCurrency>CAD</baseCurrency>
<targetCurrency>USD</targetCurrency>
<rateType>Bank of Canada noon rate</rateType>
<observationPeriod frequency="daily">2011-05-09T12:15:00-04:00</observationPeriod>
</exchangeRate>
</statistics>
</item>
</rdf>
The query /rdf/item/statistics/exchangeRate/baseCurrency doesn't fail, and returns nodes:
<baseCurrency>CAD</baseCurrency>
How do i get Microsoft XML to work with namespaces?
Edit 2
i've tried adding SelectionNamespaces to the DOMDocument object:
doc.setProperty('SelectionNamespaces', 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"');
Now the xpath query doesn't fail, but it also returns no nodes:
nodes = doc.selectNodes('/rdf:RDF/item/cb:statistics/cb:exchangeRate/cb:targetCurrency');
See also
“undeclared reference to namespace prefix ” error
XMLReader - How to handle undeclared namespace
PRB: Specifying Fully Qualified Element Names in XPath Queries
XPath not working properly.
Using SelectionNamespaces is the correct approach, you are just missing a namespace.
Notice that your XML document explicitly sets the default namespace as follows:
xmlns="http://purl.org/rss/1.0/"
This means that any element without a prefix, such as the item element, is actually in the default namespace. So if you want to select that element with an XPath expression, you must first set an appropriate selection namespace.
To do this, you can change your call to setProperty like so:
doc.setProperty('SelectionNamespaces', 'xmlns:rss="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"');
Here you've assigned the default namespace from the document to the rss: prefix in your XPath expression. With that change in place, the following XPath expression should work correctly:
nodes = doc.selectNodes('/rdf:RDF/rss:item/cb:statistics/cb:exchangeRate/cb:targetCurrency');
It works because it references the item element using the correct namespace. The fact that the prefix differs between the XPath expression and the original document is immaterial. It is the namespace which the prefix is bound to that matters.
doc.setProperty('SelectionNamespaces', 'xmlns:rss="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"');
Dont forget to load the xsd file or schema to the xmldoc object
is the way to go
I dont have enough reputation to comment. But that bit there saved me a lot of time.
Thank you so much
If you are using XMLSerializer and see this error, it is likely that you are running into the IE bug described here:
https://stackoverflow.com/a/11399681
It took me a lot of time to realize that this was happening, so I thought it best to link these two issues.
I have broken down the horribly unwieldy web.config file into individual files for some of the sections (e.g. connectionStrings, authentication, pages etc.) using the configSource attribute.
This is working fine, but the individual xml files that hold the section 'snippets' cause warnings in VS.
For example, a file named roleManager.config is used for the role manager section, and looks like this:
<roleManager enabled="false">
</rolemanager>
However I get a blue squiggle under the roleManager element in VS, and the following warning: The 'roleManager' element is not declared
I guess this is something to do with valid xml and schemas etc. Is there an easy way to fix this? Something I can add to the individual files?
Thanks
P.S. I have heard that it is bad practice to break the web.config file out like this. But don't really understand why - can anyone illuminate me?
Searching a workaround to this matter using Custom Config Files, I found this solution. Dont know if is the correct one.
The problem is that VS cant find a schema to validate your .config (xml). If you are using "native" configuration elements or when you create your custom .config files you must set to every xml document a schema.
By default (in VS9 for example) all xml files use \Microsoft Visual Studio 9.0\Xml\Schemas\DotNetConfig.xsd
but you can add more schemas to use.
Before assigning a schema you must create it.
To create a new Schema based on your own custom.config:
open your custom config file
in menubar XML->Create Schema
save it
To assign your schema:
open your custom config file
in properties panel: click on the browse button [..]
set the 'Use' column to your recently created schema
you can assign as many you want. or have one schema for all your different custom .config files
(Sorry, but my English is not so good)
I think that you get the blue squiggles since the schema of your web.config file doesn't declare these custom config sections that you've 'broken out' into individual files.
In investigating this, I see that some of my solutions have the same issue, but the config sections that are provided from microsoft DON'T have the squiggles. eg: we have extracted the appsettings and connectionstrings out into their own files, and they don't get the squiggles, but our custom ones do.
I tried to view the microsoft schema at schemas.microsoft.com/.netconfiguration/v2.0, but I get a 404 when trying to download it.
What I'm trying to say is if you get a copy of the MS schema and alter it to include your external config files, you should be able to get rid of the dreaded squiggles!
HTH,
Lance