[ 
http://issues.apache.org/jira/browse/XMLBEANS-199?page=comments#action_12323304 
] 

James Couball commented on XMLBEANS-199:
----------------------------------------

Here is the original email from the xml beans user list the prompted me to 
write this ticket:

Subject:        RE: Problem Using changeType On execQuery Result
From:   Yana Kadiyska <[EMAIL PROTECTED]>
Date:   Monday, September 12, 2005 18:31:11
To:     user@xmlbeans.apache.org; James Couball <[EMAIL PROTECTED]>

Hi James,

changeType only works successfully if AddressType is a document type. 
Currently, there is no way to type an XQuery result if the type of the element 
returned is not a document type. It's obviously a serious limitation and we're 
aware of it...you can open a bug in Jira for tracking purposes.

-----Original Message-----
From: James Couball [mailto:[EMAIL PROTECTED]
Sent: Monday, September 12, 2005 5:38 PM
To: user@xmlbeans.apache.org
Subject: Problem Using changeType On execQuery Result


I am trying to read the result of an execQuery.  My xml document (give at the 
end of this email) gives test data (namely what accounts are used for each 
test).  I have written an xquery expression to figure out the account ids to 
use for each test.

Here is the code I am trying to get to work:

            TestDataDocument testDataDocument = 
TestDataDocument.Factory.parse(new File("aws-test-data.xml"));
            String queryExpression =
                "declare namespace aws='http://test.aws.couball/data'; "+
                "for $a in /aws:test-data/aws:tests/aws:[EMAIL 
PROTECTED]'Test1']/aws:accountref/@name "+
                "return /aws:test-data/aws:accounts/aws:[EMAIL PROTECTED]";

            XmlObject[] xmlObjects = (XmlObject[]) 
testDataDocument.execQuery(queryExpression);
            log.debug("xmlObjects.length="+xmlObjects.length);
            for (XmlObject xmlObject : xmlObjects) {
                log.debug(xmlObject.getClass().getName());
                AccountType account = (AccountType) 
xmlObject.changeType(AccountType.type);
                log.debug(account.getClass().getName());
                log.debug("account.getId()="+account.getId()+", 
account.getName()="+account.getName());
            }

I believe that I am getting the right data selected in the xquery expression 
since I can use a cursor from each xmlObject and traverse to see all the nodes 
I expect.  The problem is with utilizing changeType.  The account object in my 
sample always returns null for getId() and getName().  AccountType is a 
generated xmlbeans object from my schema.  Am I missing something here with 
.changeType?  Or am I on the wrong track.  Any advice would be appreciated.

Here is the log output I receive when running this snippet:

2005-09-12 17:30:35,785 [main] DEBUG couball.aws.test.CheckCategoriesTest -
xmlObjects.length=2

2005-09-12 17:30:35,785 [main] DEBUG couball.aws.test.CheckCategoriesTest -
xmlObject.getClass().getName()=org.apache.xmlbeans.impl.values.XmlAnyTypeImpl

2005-09-12 17:30:35,785 [main] DEBUG couball.aws.test.CheckCategoriesTest -
account.getClass().getName()=couball.aws.test.data.impl.AccountTypeImpl

2005-09-12 17:30:35,785 [main] DEBUG couball.aws.test.CheckCategoriesTest -
account.getId()=null, account.getName()=null

2005-09-12 17:30:35,785 [main] DEBUG couball.aws.test.CheckCategoriesTest -
xmlObject.getClass().getName()=org.apache.xmlbeans.impl.values.XmlAnyTypeImpl

2005-09-12 17:30:35,785 [main] DEBUG couball.aws.test.CheckCategoriesTest -
account.getClass().getName()=couball.aws.test.data.impl.AccountTypeImpl

2005-09-12 17:30:35,785 [main] DEBUG couball.aws.test.CheckCategoriesTest -
account.getId()=null, account.getName()=null


The XML:

<?xml version="1.0" encoding="UTF-8"?>

    <tests>
        <test name="Test1">
            <accountref name="Account1"/>
            <accountref name="Account2"/>
        </test>
        <test name="Test2">
            <accountref name="Account2"/>
            <accountref name="Account4"/>
        </test>
        <test name="Test4">
            <accountref name="Account6"/>
            <accountref name="Account7"/>
            <accountref name="Account8"/>
            <accountref name="Account9"/>
        </test>
        <test name="Test4"/>
        <test name="Test5"/>
    </tests>
    <accounts>
        <account name="Account1" id="19a2921138"/>
        <account name="Account2" id="1142344365"/>
        <account name="Account3" id="16r5y73980"/>
        <account name="Account4" id="36fdf57a70"/>
        <account name="Account5" id="1940594337"/>
        <account name="Account6" id="387a77fda4"/>
        <account name="Account7" id="02300s7168"/>
        <account name="Account8" id="11k0131113"/>
        <account name="Account9" id="252594ae50"/>
    </accounts>
</test-data>

> Make XmlObject.changeType Work For non-document Types
> -----------------------------------------------------
>
>          Key: XMLBEANS-199
>          URL: http://issues.apache.org/jira/browse/XMLBEANS-199
>      Project: XMLBeans
>         Type: Bug
>   Components: XmlObject
>     Versions: Version 2
>  Environment: N/A
>     Reporter: James Couball

>
> Currently, XmlObject.changeType only works if the object it is performed on 
> is a document type.  Please make it work for non-document types too.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to