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

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.

Related

bjam fails the notfile example from the documentation?

I have seen boost-build / bjam: execute a script post install (make 'install' a dependency of executing a script) where there is a recommendation for using notfile. Then I found the https://www.boost.org/build/doc/html/bbv2/builtins/raw.html page with a basic example, where I've added the import notfile:
import notfile;
notfile echo_something : #echo ;
actions echo
{
echo "something"
}
And I've tried this snippet in a Jamroot file of a project. If I do not have the import notfile, then it fails with:
...
Jamroot:57: in modules.load
ERROR: rule "notfile" unknown in module "Jamfile</home/USER/src/myproject>".
/usr/share/boost-build/src/build/project.jam:372: in load-jamfile
/usr/share/boost-build/src/build/project.jam:64: in load
/usr/share/boost-build/src/build/project.jam:142: in project.find
/usr/share/boost-build/src/build-system.jam:618: in load
/usr/share/boost-build/src/kernel/modules.jam:295: in import
/usr/share/boost-build/src/kernel/bootstrap.jam:139: in boost-build
/usr/share/boost-build/boost-build.jam:8: in module scope
If I have the import notfile; then it fails with:
Jamroot:56: Unescaped special character in argument notfile;
/usr/share/boost-build/src/kernel/modules.jam:258: in modules.import from module modules
error: When loading multiple modules, no specific rules or renaming is allowed
/usr/share/boost-build/src/build/project.jam:1121: in import from module Jamfile</home/USER/src/myproject>
Jamroot:62: in modules.load from module Jamfile</home/USER/src/myproject>
/usr/share/boost-build/src/build/project.jam:372: in load-jamfile from module project
/usr/share/boost-build/src/build/project.jam:64: in load from module project
/usr/share/boost-build/src/build/project.jam:142: in project.find from module project
/usr/share/boost-build/src/build-system.jam:618: in load from module build-system
/usr/share/boost-build/src/kernel/modules.jam:295: in import from module modules
/usr/share/boost-build/src/kernel/bootstrap.jam:139: in boost-build from module
/usr/share/boost-build/boost-build.jam:8: in module scope from module
How can I get this to work?
Just noticed the "Jamroot:56: Unescaped special character in argument notfile" while writing the question which finally made sense (errors like "error: When loading multiple modules, no specific rules or renaming is allowed" are completely misleading and useless) - and I realized, I had written:
import notfile;
... that is, with semicolon directly after the word - it seems, here space is required; so with this change:
import notfile ;
... things start working again.

xquery (eXist-db) - imported module not found

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.

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.

RFT- What JAR file do i need to use 'import javax.xml.parsers.DocumentBuilder'

On my scenario, I'm trying to retrieve the information of an applicant from an XML file. I'm trying to retrieve the data of certain tags within the xml file and insert the string to an CSV file to use it as the datapool.
Im trying to use the following Imports
import javax.xml.parsers.DocumentBuilder;
import javaxxml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
When i try to use the above import classes i get an error (The import cannot be resolved)
I have added the JAR file JDOM to my project , but that didn't work.
I was using "java" instead of "javax" i'm no longer getting the error
findjar.com tells me it's in rt.jar (as of Java 6)
rt.jar contains all the RunTime classes that comprise the Java SE
platform’s core API’s. In simple terms this is the jar which contains
classes like java.lang.String, java.io package etc.
Could be Java SE or Apache Xerces or AWT
They all have the same class within same package.

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