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/05 00:01:22 UTC

RE: {SPAM?} Re: How to retrieve element's value only?

It does not work....

By replacing 
String xpath = "//User[@email='alien@alien.com']/Password";
With
String xpath = "//User[@email='alien@alien.com']/Password/text()"; 

Why?

-----Original Message-----
From: Eric Zhang [mailto:yue.zhang@ualberta.ca] 
Sent: 04 March 2004 21:52
To: xindice-users@xml.apache.org
Subject: {SPAM?} Re: How to retrieve element's value only?


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


Re: How to retrieve element's value only?

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Chen Longtai wrote:

>How to I select the element and then get the content as JDOM Document?
>
>Can give me some sample codes to see?
>
>I don't use DOM at all.
>  
>

See XMLResource.getContentAsDOM

Vadim


Re:How to retrieve element's value only?

Posted by Chen Longtai <lt...@essex.ac.uk>.
Hi,

How to I select the element and then get the content as JDOM Document?

Can give me some sample codes to see?

I don't use DOM at all.

I use the following program 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/text()";
            XPathQueryService service =
                (XPathQueryService) col.getService("XPathQueryService",
"1.0");
            ResourceSet resultSet = service.query(xpath);
     
            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();
            }
        }
    }
//----------------------------------------------------------------------
----


Thanks.

Regards.

-----Original Message-----
From: Vadim Gritsenko [mailto:vadim@reverycodes.com] 
Sent: 星期五, 5 三月, 2004 AM 1:22
To: xindice-users@xml.apache.org
Subject: Re: {SPAM?} Re: How to retrieve element's value only?

Chen Longtai wrote:

>I am running Xindice 1.0.
>
>Is there any problems?
>  
>

Yes. This feature (non-element results) are supported by xindice
1.1b4-dev only.

To get value in xindice 1.0, select element and use getContentAsDOM
method, and traverse DOM.

Vadim


>-----Original Message-----
>From: Vadim Gritsenko [mailto:vadim@reverycodes.com] 
>Sent: 星期四, 4 三月, 2004 PM 11:28
>To: xindice-users@xml.apache.org
>Subject: Re: {SPAM?} Re: How to retrieve element's value only?
>
>Tan, Leong T wrote:
>
>  
>
>>It does not work....
>> 
>>
>>    
>>
>
>Can you be more specific? Are you running current CVS or earlier
>version?
>
>  
>
>>By replacing 
>>String xpath = "//User[@email='alien@alien.com']/Password";
>>With
>>String xpath = "//User[@email='alien@alien.com']/Password/text()"; 
>> 
>>
>>    
>>
>
>
>Vadim
>



Re: {SPAM?} Re: How to retrieve element's value only?

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Chen Longtai wrote:

>I am running Xindice 1.0.
>
>Is there any problems?
>  
>

Yes. This feature (non-element results) are supported by xindice
1.1b4-dev only.

To get value in xindice 1.0, select element and use getContentAsDOM
method, and traverse DOM.

Vadim


>-----Original Message-----
>From: Vadim Gritsenko [mailto:vadim@reverycodes.com] 
>Sent: 星期四, 4 三月, 2004 PM 11:28
>To: xindice-users@xml.apache.org
>Subject: Re: {SPAM?} Re: How to retrieve element's value only?
>
>Tan, Leong T wrote:
>
>  
>
>>It does not work....
>> 
>>
>>    
>>
>
>Can you be more specific? Are you running current CVS or earlier
>version?
>
>  
>
>>By replacing 
>>String xpath = "//User[@email='alien@alien.com']/Password";
>>With
>>String xpath = "//User[@email='alien@alien.com']/Password/text()"; 
>> 
>>
>>    
>>
>
>
>Vadim
>

RE: {SPAM?} Re: How to retrieve element's value only?

Posted by Chen Longtai <lt...@essex.ac.uk>.
I am running Xindice 1.0.

Is there any problems?

-----Original Message-----
From: Vadim Gritsenko [mailto:vadim@reverycodes.com] 
Sent: 星期四, 4 三月, 2004 PM 11:28
To: xindice-users@xml.apache.org
Subject: Re: {SPAM?} Re: How to retrieve element's value only?

Tan, Leong T wrote:

>It does not work....
>  
>

Can you be more specific? Are you running current CVS or earlier
version?

>By replacing 
>String xpath = "//User[@email='alien@alien.com']/Password";
>With
>String xpath = "//User[@email='alien@alien.com']/Password/text()"; 
>  
>


Vadim




How to retrieve element's value only?

Posted by Chen Longtai <lt...@essex.ac.uk>.
Hi,

I am running Xindice 1.0 version.

I use the following program 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/text()";
            XPathQueryService service =
                (XPathQueryService) col.getService("XPathQueryService",
"1.0");
            ResourceSet resultSet = service.query(xpath);
     
            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, what I got was nothing when I print out the value of the XPath
expression: String xpath = 				
"//User[@email='alien@alien.com']/Password/text()";

Why? Please help.

Regards,
longtai

-----Original Message-----
From: Vadim Gritsenko [mailto:vadim@reverycodes.com] 
Sent: 星期四, 4 三月, 2004 PM 11:28
To: xindice-users@xml.apache.org
Subject: Re: {SPAM?} Re: How to retrieve element's value only?

Tan, Leong T wrote:

>It does not work....
>  
>

Can you be more specific? Are you running current CVS or earlier
version?

>By replacing 
>String xpath = "//User[@email='alien@alien.com']/Password";
>With
>String xpath = "//User[@email='alien@alien.com']/Password/text()"; 
>  
>


Vadim




Re: {SPAM?} Re: How to retrieve element's value only?

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Tan, Leong T wrote:

>It does not work....
>  
>

Can you be more specific? Are you running current CVS or earlier version?

>By replacing 
>String xpath = "//User[@email='alien@alien.com']/Password";
>With
>String xpath = "//User[@email='alien@alien.com']/Password/text()"; 
>  
>


Vadim