[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xindice-dev
Subject:    Patch for namespaces in xpath queries
From:       Vanessa Williams <v.williams () acm ! org>
Date:       2002-06-26 21:34:28
[Download RAW message or body]

If you like, apply these patches to org.apache.xindice.tools.XMLTools.java
and org.apache.xindice.tools.command.XPathQuery.java.

Then, use the following command to use namespaces with an xpath query:

xindice -c /db/mycollection -s "a=http://www.somedomain.com/schema1.xsd" -q
"/a:foo"

Or type xindice -h for help.

Enjoy,

Vanessa


["XMLTools_patch.txt" (application/octet-stream)]

*** java/src/org/apache/xindice/tools/XMLTools.java	Wed Jun 26 17:25:09 2002
--- /Users/vwilliam/Desktop/patched/XMLTools.java	Wed Jun 26 16:22:40 2002
***************
*** 114,119 ****
--- 114,120 ----
      public static final String USER = "user";
      public static final String PASSWORD = "password";
      public static final String AUTO_KEY = "autoKey";
+     public static final String NAMESPACES = "namespaces";
  
  
  
***************
*** 236,241 ****
--- 237,244 ----
                 table.put( VERBOSE, "true");
              } else if ( token.equalsIgnoreCase("-y") || \
token.equalsIgnoreCase("--yes_force") ) {  table.put( FORCE, "yes");
+             } else if ( token.equalsIgnoreCase("-s") || \
token.equalsIgnoreCase("--namespaces") ) { +             	table.put(NAMESPACES, \
at.nextSwitchToken());  // Index specific options
              } else if ( token.equalsIgnoreCase("-t") || \
token.equalsIgnoreCase("--type") ) {  table.put( TYPE, at.nextSwitchToken());
***************
*** 632,637 ****
--- 635,641 ----
        System.out.println("    -q           " + "Query string");
        System.out.println("    -u           " + "Database URI");
        System.out.println("    -y           " + "Force Deletion process");
+       System.out.println("    -s           " + "Semi-colon delimited list of \
                namespaces for query in the form prefix=namespace-uri");
        System.out.println("    -t           " + "Specify the data type in collection \
                index");
        System.out.println("    --pagesize   " + "Page size for file pages (default: \
                4096)");
        System.out.println("    --maxkeysize " + "The maximum size for file keys \
                (default: 0=none)");
***************
*** 670,675 ****
--- 674,680 ----
        System.out.println("    xindice dd -c /db/test -n myxmldocument");
        System.out.println("    xindice rd -c /db/test/ocs -f a:\\file.xml -n \
file.xml");  System.out.println("    xindice xpath -c /db/test/ocs -q test");
+       System.out.println("    xindice xpath -c /db/test -s \
a=http://somedomain.com/schema.xsd -q /a:foo");  System.out.println();
        System.out.println("For more information, please read the Xindice - Tools \
Reference Guide");  System.out.println();


["XPathQuery_patch.txt" (application/octet-stream)]

*** java/src/org/apache/xindice/tools/command/XPathQuery.java	Wed Jun 26 17:17:55 2002
--- /Users/vwilliam/Desktop/patched/XPathQuery.java	Wed Jun 26 16:59:00 2002
***************
*** 60,65 ****
--- 60,66 ----
   */
  
  import java.util.Hashtable;
+ import java.util.StringTokenizer;
  import java.io.*;
  
  import org.xmldb.api.modules.*;
***************
*** 93,98 ****
--- 94,100 ----
                  return false;
              }
              
+             
              String colstring = normalizeCollectionURI( (String)table.get("collection") );
              String querystring = (String)table.get("query");
              XPathQueryService service = null;
***************
*** 106,111 ****
--- 108,115 ----
              }
              
              service = (XPathQueryService)col.getService("XPathQueryService","1.0");
+             addNamespaces(service, (String)table.get("namespaces"));
+             
              ResourceSet resultSet = service.query(querystring);
              results = resultSet.getIterator();
              
***************
*** 131,136 ****
--- 135,152 ----
        return true;
     }
  
+ 	private void addNamespaces(XPathQueryService service, String namespacesString) throws XMLDBException {
+ 		if ((namespacesString != "") && (namespacesString != null)) {
+ 			StringTokenizer st = new StringTokenizer(namespacesString, "=;");
+ 			if (st.countTokens() % 2 != 0) {
+ 				System.out.println("ERROR : mismatched namespace prefixes and uris");
+ 				return;
+ 			}
+ 			while (st.hasMoreTokens()) {
+ 				service.setNamespace(st.nextToken(), st.nextToken());
+ 			}
+ 		}
+ 	}
  }
  
  


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic