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>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]