Namespace declarations in a search
You must define QName prefixes and default element namespaces in the XPath query prolog of the search term.
If a query does not declare any QName prefix or default element namespace, namespaces are not considered in the query. If an element or attribute name exists in any namespace, the element or attribute name is considered a match. If any QName prefix or default namespace is declared, element or attribute names are a match only if they exist in the namespace that is specified. QName prefixes used in the XML search string are not required to match the QName prefix that is used in the XML document. Matches are based solely on the URI.
The following prolog maps namespace ns1 to long name (URI) "http://mycompany.com":
declare namespace ns1 = "http://mycompany.com"; In this next example, the prolog specifies that all unqualified elements are qualified by URI "http://mycompany.com":
declare default element namespace "http://mycompany.com"The following syntax could be used to indicate that unqualified tags are not in any namespace:
declare default element namespace "”; Consider these additional examples when defining namespaces.
Example
1: The following example restricts search to attribute attr of
element test, where element test is
mapped to namespace "http://posample.org",
and attr is not in any namespace.
Use default namespace to simplify the syntax.
CONTAINS(myxmlcol, '@xmlxp:''declare default element namespace
“http://myexample.org”;
/test[@attr > xs:date(“2005-01-01”)]''')Example
2: This next example restricts search to attribute attr of
element test, where element test has
a namespace of "http://myexample.org".
Use explicit namespace syntax by using the QName prefix abc.
CONTAINS(myxmlcol, '@xmlxp:''declare namespace abc = “http://myexample.org”;
/abc:test[@attr < xs:date(“2009-01-01”)]''')Example
3: This example restricts search to shipTo name and billTo name child
elements of element purchaseOrder, which is explicitly
mapped to namespace "http://myexample.org" using QName prefix ns1.
A default namespace is also defined ("http://mastsample.org"),
which applies to shipTo, name, and billTo.
CONTAINS(myxmlcol, '@xmlxp:'' declare default namespace "http://mastsample.org";
declare namespace ns1 = "http://posample.org";
/ns1:purchaseOrder[shipTo/name = "Jane" and billTo/name = "Jason"]''')Example
4: This example restricts search to attribute name (explicitly
defined in namespace "http://posample.org") of
shipTo element (in default namespace "http://mastsample.org"),
which is a child of element purchaseOrder (explicitly
defined in namespace "http://posample.org").
The default namespace "http://mastsample.org" applies
to elements shipTo, billTo and name.
CONTAINS(myxmlcol, '@xmlxp:'' declare default namespace "http://mastsample.org";
declare namespace ns1 = "http://posample.org";
/ns1:purchaseOrder/shipTo[@ns1:name = "Jane" and billTo/name = "Jason"]''')