You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by "Tan, Leong T" <lt...@essex.ac.uk> on 2004/03/04 22:42:37 UTC

How to retrieve element's value only?

Hi,

I used to follow code to get the value of password element:

public static void main(String[] args) throws Exception {
        Collection col = null;
        try {
            String driver =
"org.apache.xindice.client.xmldb.DatabaseImpl";
            Class c = Class.forName(driver);

            Database database = (Database) c.newInstance();
            DatabaseManager.registerDatabase(database);

            col =
DatabaseManager.getCollection("xmldb:xindice:///db/User");

            String xpath = "//User[@email='alien@alien.com']/Password";
            XPathQueryService service =
                (XPathQueryService) col.getService("XPathQueryService",
"1.0");
            ResourceSet resultSet = service.query(xpath);
            /*if (resultSet.getSize()!=1){
                System.out.println( "wrong");
            }
            else{
 
System.out.println(resultSet.getResource(0).getContent());
            }
 
            ResourceIterator results = resultSet.getIterator();
            
            while (results.hasMoreResources()) {
                Resource res = results.nextResource();
                System.out.println((String) res.getContent());
            }
            
        }
        catch (XMLDBException e) {
            System.err.println("XML:DB Exception occured " +
e.errorCode);
        }
        finally {
            if (col != null) {
                col.close();
            }
        }
    }

//--------------------------------------------------------------

However it return the result:

<?xml version="1.0"?>
<Password xmlns:src="http://xml.apache.org/xindice/Query"
src:col="/db/User" src:key="alienUser">1234567
</Password>

I just want to value "1234567" but without the element tag, how should I
do it?

Regards,
longtai

Re: How to retrieve element's value only?

Posted by Eric Zhang <yu...@ualberta.ca>.
probably try //User[@email='alien@alien.com']/Password/text()
instead..


On Thu, 2004-03-04 at 14:42, Tan, Leong T wrote:
> Hi,
> 
> I used to follow code to get the value of password element:
> 
> public static void main(String[] args) throws Exception {
>         Collection col = null;
>         try {
>             String driver =
> "org.apache.xindice.client.xmldb.DatabaseImpl";
>             Class c = Class.forName(driver);
> 
>             Database database = (Database) c.newInstance();
>             DatabaseManager.registerDatabase(database);
> 
>             col =
> DatabaseManager.getCollection("xmldb:xindice:///db/User");
> 
>             String xpath = "//User[@email='alien@alien.com']/Password";
>             XPathQueryService service =
>                 (XPathQueryService) col.getService("XPathQueryService",
> "1.0");
>             ResourceSet resultSet = service.query(xpath);
>             /*if (resultSet.getSize()!=1){
>                 System.out.println( "wrong");
>             }
>             else{
>  
> System.out.println(resultSet.getResource(0).getContent());
>             }
>  
>             ResourceIterator results = resultSet.getIterator();
>             
>             while (results.hasMoreResources()) {
>                 Resource res = results.nextResource();
>                 System.out.println((String) res.getContent());
>             }
>             
>         }
>         catch (XMLDBException e) {
>             System.err.println("XML:DB Exception occured " +
> e.errorCode);
>         }
>         finally {
>             if (col != null) {
>                 col.close();
>             }
>         }
>     }
> 
> //--------------------------------------------------------------
> 
> However it return the result:
> 
> <?xml version="1.0"?>
> <Password xmlns:src="http://xml.apache.org/xindice/Query"
> src:col="/db/User" src:key="alienUser">1234567
> </Password>
> 
> I just want to value "1234567" but without the element tag, how should I
> do it?
> 
> Regards,
> longtai
-- 
Yue(Eric) Zhang
Database Analyst/DBA, TAPoR Project
Arts Department, University of Alberta
Edmonton, AB, Canada


Remote connection problem if connecting thru a web service

Posted by sangram vajre <sa...@yahoo.com>.
hi All,

 When I execute the following statement through a Java web service
 it throughs an exception that "connot connect to the host <server_name>"

 DatabaseManager.getCollection("xmldb:xindice://server_name:4080/db/collecton_name");
 
 But when I run the same program remotely through a DOS-Prompt, the connection
 works. Any help will be apprecaited. I am in badly need of some solution of this.

Thanks,
San
 
 


=====
***Expectations are the worst enemy in any relation***

With Regards,

 Sangram Vajre
 University of Alabama
 Computer Science Graduate Student 
 417,Reed Street Apt. 4B
 Tuscaloosa,AL
 Phone 205-344-4580

__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com