@@ -539,7 +539,7 @@ private boolean defaultNamespaceDecl(final boolean fixed) throws QueryException
539539 final boolean elem = wsConsumeWs (ELEMENT );
540540 if (!elem && !wsConsumeWs (FUNCTION )) return false ;
541541 wsCheck (NAMESPACE );
542- final byte [] uri = uriLiteral ();
542+ final byte [] uri = elem ? uriLiteral ( ANY_URI ) : uriLiteral ();
543543 if (eq (XML_URI , uri )) throw error (BINDXMLURI_X_X , uri , XML );
544544 if (eq (XMLNS_URI , uri )) throw error (BINDXMLURI_X_X , uri , XMLNS );
545545
@@ -697,7 +697,6 @@ private void schemaImport() throws QueryException {
697697 }
698698 final byte [] uri = uriLiteral ();
699699 if (prefix != null && uri .length == 0 ) throw error (NSEMPTY );
700- if (!Uri .get (uri ).isValid ()) throw error (INVURI_X , uri );
701700 addLocations (new TokenList ());
702701 throw error (IMPLSCHEMA );
703702 }
@@ -715,7 +714,6 @@ private void moduleImport() throws QueryException {
715714
716715 final byte [] uri = uriLiteral ();
717716 if (uri .length == 0 ) throw error (NSMODURI );
718- if (!Uri .get (uri ).isValid ()) throw error (INVURI_X , uri );
719717 if (sc .imports .contains (token (uri ))) throw error (DUPLMODULE_X , uri );
720718 sc .imports .add (uri );
721719
@@ -754,8 +752,7 @@ private boolean addLocations(final TokenList list) throws QueryException {
754752 if (add ) {
755753 do {
756754 final byte [] uri = uriLiteral ();
757- if (!Uri .get (uri ).isValid () || IO .get (string (uri )) instanceof IOContent )
758- throw error (INVURI_X , uri );
755+ if (IO .get (string (uri )) instanceof IOContent ) throw error (INVURI_X , uri );
759756 list .add (uri );
760757 } while (wsConsume ("," ));
761758 }
@@ -2467,7 +2464,8 @@ private ExprInfo simpleNodeTest(final Kind kind, final boolean all) throws Query
24672464 name = new QNm (concat (name .string (), cpToken (':' )));
24682465 scope = NameTest .Scope .URI ;
24692466 } else if (!eqName ) {
2470- scope = NameTest .Scope .FLEXIBLE ;
2467+ scope = kind == Kind .ELEMENT && eq (sc .elemNS , ANY_URI ) ? NameTest .Scope .LOCAL
2468+ : NameTest .Scope .FLEXIBLE ;
24712469 }
24722470 }
24732471 // name test: prefix:name, name, Q{uri}name
@@ -2878,11 +2876,15 @@ private byte[] stringLiteral() throws QueryException {
28782876
28792877 /**
28802878 * Parses the "URILiteral" rule.
2879+ * @param special tokens that are allowed though not valid URI literals
28812880 * @return query expression
28822881 * @throws QueryException query exception
28832882 */
2884- private byte [] uriLiteral () throws QueryException {
2885- return normalize (stringLiteral ());
2883+ private byte [] uriLiteral (final byte []... special ) throws QueryException {
2884+ final byte [] uri = normalize (stringLiteral ());
2885+ for (final byte [] sp : special ) if (eq (uri , sp )) return uri ;
2886+ if (!Uri .get (uri ).isValid ()) throw error (INVURI_X , uri );
2887+ return uri ;
28862888 }
28872889
28882890 /**
@@ -2898,6 +2900,7 @@ private byte[] bracedURILiteral() throws QueryException {
28982900 entity (token );
28992901 }
29002902 final byte [] ns = normalize (token .toArray ());
2903+ if (!Uri .get (ns ).isValid ()) throw error (INVURI_X , ns );
29012904 if (eq (ns , XMLNS_URI )) {
29022905 pos = p ;
29032906 throw error (ILLEGALEQNAME_X , ns );
@@ -3471,7 +3474,7 @@ private SeqType castTarget() throws QueryException {
34713474 if (wsConsume ("(" )) {
34723475 type = choiceItemType ().type ;
34733476 } else {
3474- final QNm name = eQName (sc .elemNS , TYPEINVALID );
3477+ final QNm name = eQName (eq ( sc . elemNS , ANY_URI ) ? XS_URI : sc .elemNS , TYPEINVALID );
34753478 if (!name .hasURI () && eq (name .local (), token (ENUM ))) {
34763479 if (!wsConsume ("(" )) throw error (WHICHCAST_X , BasicType .similar (name ));
34773480 type = enumerationType ();
@@ -3560,8 +3563,8 @@ private SeqType itemType() throws QueryException {
35603563 }
35613564 }
35623565 } else {
3563- // attach default element namespace
3564- if (!name .hasURI ()) name .uri (sc .elemNS );
3566+ // attach default element namespace, or schema namespace if default element namespace is ##any
3567+ if (!name .hasURI ()) name .uri (eq ( sc . elemNS , ANY_URI ) ? XS_URI : sc .elemNS );
35653568 // basic type
35663569 type = BasicType .get (name , false );
35673570 // declared type
0 commit comments