Problem with "import module"
Added by Anonymous about 20 years ago
Legacy ID: #2781064 Legacy Poster: Ralf Lemke (olaf35)
Hi, I've got am XML file in c:\rle\Quellen\Java\javacc\javacc-3.2\bin\MetaModel.xml
that i want to query with multiple query-files, that uses the same functions. That's
why, i wrote a c:\rle\Quellen\Java\Metiken\LocalFunctions.xql library module: xquery
version "1.0"; module namespace jmt2 =
"file://pclera/rle/Quellen/Java/Metriken/LocalFunctions"; declare
function jmt2:tree ($GeneralizableElements as element()*, $dit as xs:integer) as
xs:integer { ... To Access this file I wrote a query-file:
c:\rle\Quellen\Java\Metriken\SingleClassMetrics\DIT.xql xquery version
"1.0"; (: DIT Metrik :) declare base-uri
"file://pclera/rle/Quellen/Java/Metriken"; import module namespace
jmt2func = "base-uri/LocalFunctions" at
"base-uri/LocalFunctions.xql" (: Root des UML-Abschnitts :) let
$UMLModel :=
fn:doc("base-uri/../javacc/javacc-3.2/bin/MetaModel.xml")/XMI/XMI.content/Model_Management.Model
... Without the library module (functions includes in the query-file) the query works.
The MetaModel.xml-file was found with this uri. The import of the library module doesn't
work. I get an error message : Error XQuery syntax error on line 9 of
file://pclera/rle/Quellen/Java/Metriken in ...t des UML-Abschnitts :) let $
:
java.net.ConnectException: Connection refused: connect Error XQuery syntax error on line
39 of file://pclera/rle/Quellen/Java/Metriken in ...return fn:data(<p>DIT : {$dit}
: Variable $dit has not been declared Failed to compile query: XQuery syntax
error Query processing failed: net.sf.saxon.xpath.StaticError: XQuery syntax error Can
You help me? Thanks Ralf.
Replies (4)
Please register to reply
RE: Problem with "import module" - Added by Anonymous about 20 years ago
Legacy ID: #2781929 Legacy Poster: Michael Kay (mhkay)
You shouldn't normally need to specify a base URI explicitly in the query, it will be picked up automatically when you read the query from a file. And you can't refer to the base URI by putting "base-uri" at the start of your relative URI. URI resolution works the same way as in HTML: if A.xq and B.xq are in the same directory, then A can refer to the relative URI "B.xq"; if B.xq is in the parent directory of A, the relative URI can be "../B.xq" and so on. Alternatively use absolute URIs, which will normally be "file:///" followed by the full file name. (I guess "pclera" is the name of your machine? You don't need to specify that).
RE: Problem with "import module" - Added by Anonymous about 20 years ago
Legacy ID: #2789424 Legacy Poster: Ralf Lemke (olaf35)
Sorry, I was a few days absent. Thank You for Your answaer. However, I've
experimented, but it doesn't work. If I cut the host "pclera" from the
uri, I get an error message, that the host "c" is unknown. If I use
absolute URIs, my problem is not resolved. I can't connect to my library module file and
I don't know what is the reason. Copying the library module file into the same path as
the query file is, produce the same error. The parent path C:\rle is shared. I guess the
problem maybe happens with namespaces or with the uri-String itself ... I is not a big
problem, if I can't use a library module, but it was a little bit more elegant. Query
file: xquery version "1.0"; (: DIT Metrik :) (: declare base-uri
"file://pclera/rle/Quellen/Java/Metriken"; :) import module namespace
jmt2func =
"file://PCLERA/c/rle/Quellen/Java/Metriken/SingleClassMetrics/LocalFunctions.xql"
at
"file://PCLERA/c/rle/Quellen/Java/Metriken/SingleClassMetrics/LocalFunctions.xql"
(: Root des UML-Abschnitts :) let $UMLModel :=
fn:doc("file://PCLERA/c/rle/Quellen/Java/javacc/javacc-3.2/bin/MetaModel.xml")/XMI/XMI.content/Model_Management.Model
(: Zugriff auf alle GeneralizableElements :) let $GeneralizableElements :=
$UMLModel//Core.Generalization (: Der vollständige Klassenname aus der Datei
TestClass.xml :) let $FullClassName :=
fn:data(fn:doc("file://PCLERA/c/rle/Quellen/Java/javacc/javacc-3.2/bin/TestClass.xml")/Class)
(: Tokenizer-Funktion erzeugt eine Sequenz - aus org.argouml.xml.xmi.XMIReader wird
("org", "argouml", :) (: "xml",
"xmi", "XMIReader") :) let $tokens :=
fn:tokenize($FullClassName, ".") (: Suche die richtige Klasse im
richtigen Package :) let $Class := if(fn:count($tokens) > 1) then
jmt2func:findClass($UMLModel, $tokens) else
if($UMLModel/Core.Namespace.ownedElement/Model_Management.Package/@name = $FullClassName
) then $UMLModel/Core.Namespace.ownedElement/Model_Management.Package[@name =
$FullClassName] else $UMLModel/Core.Namespace.ownedElement/Core.UmlClass[@name =
$FullClassName] (: Nur die GeneralizableElements der Klasse $ClassName :) let
$GeneralizableElements := for $Childs in $GeneralizableElements where $Childs/@child =
$Class/@xmi.id return $Childs (: Initialisieren :) let $dit := 0 let $dit :=
if(fn:count($GeneralizableElements) > 0) then
jmt2func:tree($GeneralizableElements, $dit) else $dit return
fn:data(<p>DIT : {$dit}</p>) library module: xquery version
"1.0"; (: URI - schema://[benutzer[:passwort]@]host[:port]/pfad :) (:
schema - z. B. http, ftp, gopher, telnet, file usw. siehe
www.tele-task.de/player/embedded. php?series=59&lecture :) (: declare base-uri
"file://ralf/e/Schule/Diplom/Jmt2/Metriken"; :) module namespace jmt2
=
"file://PCLERA/c/rle/Quellen/Java/Metriken/SingleClassMetrics/LocalFunctions.xql";
declare function jmt2:tree ($GeneralizableElements as element(), $dit as xs:integer) as
xs:integer { let $ctr := $dit + 1 (: Childs muss hier so gesetzt werden, da z. B. eine
Schleife mit einer Sequenz ein riesiges Tupel erzeugt :) (: for $Parents in
$GeneralizableElements, $Childs in $GeneralizableElements ... geht hier nicht!!! :) let
$Childs := $GeneralizableElements (: Selektiert alle Elements deren Parent-Attribute in
den Child-Attributen enthalten sind :) let $GeneralizableElements := for $Parents in
$GeneralizableElements where ($Parents/@parent = $Childs/@child) return $Parents let
$ctr := if(fn:count($GeneralizableElements) > 0) then
tree($GeneralizableElements, $ctr) else $ctr return $ctr }; (: Diese Funktion navigiert
durch die Packages zur richtigen Klasse, der Klassenname wird in TestClass.xml :) (: in
der Form z. B. org.argouml.xml.xmi.XMIReader angegeben. im UML-Abschnitt des Metamodels
sind die :) (: Packages aber in den Namensräumen verschachtelt :) declare function
jmt2:findClass ($Package as node(), $tokens as item()) as node() { let $count :=
fn:count($tokens) let $Package :=
if($Package/Core.Namespace.ownedElement/Model_Management.Package/@name = $tokens[1] )
then $Package/Core.Namespace.ownedElement/Model_Management.Package[@name = $tokens[1]]
else $Package/Core.Namespace.ownedElement/Core.UmlClass[@name = $tokens[1]] let $Package
:= if($count > 1) then findClass($Package, fn:subsequence($tokens, 2)) else
$Package return $Package }; Error message: Error XQuery syntax error on line 10 of
file:/C:/rle/Quellen/Java/Metriken/./SingleClassMetrics/DIT.xql in ...t des UML-Abschnitts :) let $
: java.net.ConnectException: Connection refused: connect Error
XQuery syntax error on line 40 of
file:/C:/rle/Quellen/Java/Metriken/./SingleClassMetrics/DIT.xql in ...return fn:data(<p>DIT : {$dit}
: Variable $dit has not been declared Failed to
compile query: XQuery syntax error Query processing failed:
net.sf.saxon.xpath.StaticError: XQuery syntax error The file
"MetaModel.xml" is very big, but it is similar to an UML-export-xmi
file. I would happy if everyone has an idea. Sorry for my bad english. Thanks Ralf.
RE: Problem with "import module" - Added by Anonymous about 20 years ago
Legacy ID: #2789668 Legacy Poster: Michael Kay (mhkay)
Here's a simple example that might help you get started and resolve your misunderstandings. In c:\temp\test.xq, enter: ======================== import module namespace foo="http://foo.com/" at "test.qmod"; foo:go() ======================== In c:\temp\test.qmod, enter: ======================== module namespace foo = "http://foo.com/"; declare function foo:go() as xs:string { "Go get it!" }; ======================== On the command line, do: java net.sf.saxon.Query c:\temp\test.xq The output should be <?xml version="1.0" encoding="UTF-8"?>Go get it! Saxon is resolving the relative module URI (after "at") against the base URI of the main module. Saxon knows this base URI because the query was supplied in a file with a known file name. If you supplied the query as a string, or from an anonymous Reader, then you would need to declare the base URI in the query prolog. Michael Kay Saxonica Limited
RE: Problem with "import module" - Added by Anonymous about 20 years ago
Legacy ID: #2790642 Legacy Poster: Ralf Lemke (olaf35)
Thank You for Your help. Now it works! The reason was, that I have to use a relative URI in the "at"-location. Thanks Ralf.
Please register to reply