xquery (eXist-db) - imported module not found - global-variables

I have a file "globalvar.xql" which contains what I hope can be a central document for all my non-varying variables (parameters really).
In order to use these, I understand that I have to declare/import the module into any other document that will use them. In this case, I want to use them in the functions found in "person.xql". As such, I have tried a declaration:
import module namespace globalvar="/db/apps/deheresi/modules/globalvar.xqm";
But I get the error message when I validate:
Cannot compile xquery: exerr:ERROR error found while loading module globalvar: Error while loading module /db/apps/deheresi/modules/globalvar.xqm: namespace URI declared by module (/db/apps/deheresi/modules/globalvar) does not match namespace URI in import statement, which was: /db/apps/deheresi/modules/globalvar.xqm
Error, code and directory are picture below.
I've been trying to imitate the code found in the eXist-db demos, and looking at other resources, but the error is mystifying me.
Many thanks.

In your module import declaration, you've conflated the target module's namespace URI and location URI.
To fix it, you'll need to (1) add the namespace URI where you currently have the location URI, (2) add an at clause, and (3) move the location URI to its correct location following the at clause.
In other words, it should look like this:
import module namespace globalvar="globalvar-namespace-uri" at "/db/apps/deheresi/modules/globalvar.xqm";
Of course, "globalvar-namespace-uri" here is just a placeholder for the target module's namespace URI. It will need to match the namespace URI defined in the target module.

Related

Can we define module namespace for a file that exist at the same directory level as rewrite.xqy?

I have a file that exist at the same level as rewrite.xqy i.e. it doesn't exist inside a particular directory. When i am declaring a module namespace for it, I get the following error-
<error:message>Cannot evaluate library module</error:message>
<error:format-string>XDMP-EVALLIBMOD: Cannot evaluate library module:
What is the logic behind this as when I remove module namespace it works just fine. These are the starting lines of my file-
xquery version "1.0-ml";
module namespace adv = "http://***/***/adv";
import module namespace search = "http://marklogic.com/appservices/search"
at "/Marklogic/appservices/search/search.xqy";
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
xdmp:set-response-content-type("text/html; charset=utf-8"),
<html xmlns="http://www.w3.org/1999/xhtml">
When you define a module namespace, your module is expected to be a library module with a collection of functions. You don't "run" a library module though. If you attempt to run this code, for example by pasting into QConsole, you will get the XDMP-EVALLIBMOD error.
A main module is expected to be executed as an XQuery program. Remove the module namespace module namespace adv = "http://***/***/adv";, and it will execute without error.
Or you can insert the code as a library module with the logic enclosed as the body of a function, import that module in a main module and call the function.
The error
<error:message>Cannot evaluate library module</error:message>
<error:format-string>XDMP-EVALLIBMOD: Cannot evaluate library module:
Means you are attempting to directly evaluate your code/module not import it.
How are you getting this error ?
For a xquery module, you cannot invoke it directly, you must import it in another file (usually the one you are invoking).
XQuery does not allow a single file to be both a main entry point and a module.
When you say it 'works just fine' -- thats a good place to stop.

Saxon XQuery catalog files to override DTD URI?

I am trying to use a catalog file to override DTD location in XML files. I tried following all of the tips here How to use saxon built-in catalog feature but have been unable to get it to work. I reduced to this simple example:
Confirmed version of Saxon:
C:\test>java net.sf.saxon.Query
No query file name
Saxon-HE 9.7.0.7J from Saxonica
...
My catalog file. I tried to reduce to simplest (uriSuffix):
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<uriSuffix uriSuffix="bad.dtd" uri="good.dtd" />
</catalog>
Confirmed resolver is in classpath and behaving as expected with catalog:
C:\test>java org.apache.xml.resolver.apps.resolver -c didcat.xml -u bad.dtd uri
Cannot find CatalogManager.properties
Resolve URI (uri):
uri: bad.dtd
Result: file:/C:/test/good.dtd
Simple test.xml file:
<?xml version="1.0"?>
<!DOCTYPE a SYSTEM "bad.dtd">
<a>hello world</a>
Simple test.xql:
doc("test.xml")/a
Results:
C:\test>java net.sf.saxon.Query -t -catalog:didcat.xml test.xql
Loading catalog: didcat.xml
Saxon-HE 9.7.0.7J from Saxonica
Java version 1.8.0_101
Analyzing query from test.xql
Analysis time: 131.650519 milliseconds
Resolved URI: test.xml
file:/C:/test/test.xml
Building tree for file:/C:/test/test.xml using class net.sf.saxon.tree.tiny.TinyBuilder
Error on line 2 column 6 of test.xql:
FODC0002: I/O error reported by XML parser processing file:/C:/test/test.xml:
C:\test\bad.dtd (The system cannot find the file specified)
Query failed with dynamic error: I/O error reported by XML parser processing file:/C:/test/test.xml: C:\test\bad.dtd (The system cannot find the file specified)
I tried a few different catalog techniques to override the DTD URI but none were successful. What am I doing wrong? Thanks in advance.
To resolve references to XML entities such as DTDs, you need to use the systemSuffix entry in the catalog, not the uriSuffix entry. Change your catalog to
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<systemSuffix systemSuffix="bad.dtd" uri="good.dtd" />
</catalog>

xquery error library modules cannot be evaluated or no namespace declared

When I deploy modules in JBoss, I'm getting errors:
Library modules cannot be evaluated.
Function 'hello' is in reserved namespace.
No namespace declared for 'm:hello'.
xquery version "3.0" encoding "utf-8";
import module namespace m = 'http://basex.org/modules/Hello' at 'HelloWorld2.xq';
m:hello("Universe")
I already had Helloworld2.xq file in my src/main/resources. It is not recognizing or showing as duplicate namespace. Can anyone help me with this?
Unless you are the owner of the domain "basex.org", you should probably use a different namespace for functions you write. Create a namespace in a part of URI space for which you actually do have some naming rights. That should clear at least the second error.
What relative URI to use to find a module appears to be a frequent source of confusion; if you are using BaseX, be sure to read the BaseX documentation on configuring BaseX via web.xml.

Wrap resources inside custom class and invoke class?

I am using Puppet 3.0. I tried to use the existing NGINX module but encountered one issue which no answer seems to exist. I have moved to implementing NGINX module myself which handles my exact requirements.
Each package/service/file resource works as expected and now I am moving the code out of init.pp into a /manifest/nginx.pp fileas a class:
class company_nginx {
... Various resources
}
Now I am trying to include this class inside the init.pp
include company_nginx
An it returns an error:
Error: Could not find class nginx for localhost on node localhost
What step or concept am I missing? How do I invoke this "class" in the init.pp file to get the resources invoked and configuring a system???
Manifest file names and the classes defined within them must exactly match. If you want to have a class names company_nginx then it must be in a file names company_nginx.pp.
This required comes from the puppet autoloader.
Your class names must be qualified for Puppet to be able to pick them up.
class nginx::company_nginx { ... }
This class will be loaded from module nginx file manifests/company_nginx.pp.
Doing include company_nginx will make Puppet assume that there is an actual module names company_nginx with the class defined in init.pp.

could not resolve <local:Item> to a component implementation

I am trying to implement item rendere example from TourdeFlex application. However, when I tried to run the application its giving me " could not resolve to a component implementation" error message beside the local items. I also added the assets folder and verified the visualization.swc.
Please let me know the solution to fix the issue.
THanks in advance.
Serenity.
local is XML namespace declared at the top of example, its like import in ActionScript. "Could not resolve" means referenced class is not found. Look at that namespace to determine where it must be placed. For example, xmlns:gui="gui.*" declares namespace gui which references classes from folder "gui".
Edit: xmlns:local="*" means "import all files from src directory". In src should be file Item.mxml or Item.as and it is missing (or failed to compile).

Resources