You need to sign in to do that
Don't have an account?
Kaja
wanted to fetch ONLY 42.4351 which is the value of sf:ConversionRate and store it in double variable.. Thats all my requirement.
Anyone knows how to do this using com.bea.xml.XmlObject api methods?
how to parse the child element's value using com.bea.xml.XMLObject?
Hello,
I am trying to fetch the particular element's value using XMLObject(com.bea.xml.XMLObject).
Code:
String currQuery = "Select ISOCode, ConversionRate, IsActive from CurrencyType where IsActive = True and ISOCODE = '"+oppCurrencyISOCode+"'"; QueryResult qrCurr = sfdcCtrl.query(currQuery); XmlObject xmlObj = XmlObject.Factory.parse(qrCurr.getRecordsArray(0).xmlText());
Generated XMl file from xmlObj look like below:
Code:
<xml-fragment xsi:type="sf:CurrencyType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <sf:ConversionRate xmlns:sf="urn:sobject.enterprise.soap.sforce.com">42.4351</sf:ConversionRate> <sf:IsActive xmlns:sf="urn:sobject.enterprise.soap.sforce.com">true</sf:IsActive> <sf:IsoCode xmlns:sf="urn:sobject.enterprise.soap.sforce.com">INR</sf:IsoCode> </xml-fragment>
Code:
String currQuery = "Select ISOCode, ConversionRate, IsActive from CurrencyType where IsActive = True and ISOCODE = '"+oppCurrencyISOCode+"'"; QueryResult qrCurr = Ctrl.query(currQuery); XmlObject xmlObj = XmlObject.Factory.parse(qrCurr.getRecordsArray(0).xmlText()); XmlCursor cur = xmlObj.newCursor(); while ( cur.hasNextToken ()) { String tokenInfo = collectTokenTypeInfo ( cur ) + "\n\n" ; responseBuffer.append ( tokenInfo ) ; cur.toNextToken () ; } cur.dispose () ; private String collectTokenTypeInfo ( XmlCursor cursor ){ String response = null ; XmlOptions options = new XmlOptions () ; switch ( cursor.currentTokenType () .intValue ()){ case TokenType.INT_STARTDOC: /*response = cursor.currentTokenType () + "; cursor is at the very beginning of the document, before any markup." ; */ break ; case TokenType.INT_START: /*response = cursor.currentTokenType () + "; cursor is just before this element's start: \n" + cursor.xmlText ( options ) ; */ break ; case TokenType.INT_ATTR: response = cursor.currentTokenType () + "; cursor is just before this attribute: \n"+ cursor.getTextValue () ; //response = cursor.getChars (); break ; case TokenType.INT_TEXT: response = cursor.currentTokenType () + "; cursor is just before this text (may be whitespace): \n" + cursor.getChars () ; // response = cursor.getChars (); break ; case TokenType.INT_NAMESPACE: /*response = cursor.currentTokenType () + "; cursor is just before this namespace: \n" + cursor.xmlText () ; */ break ; case TokenType.INT_COMMENT: /*response = cursor.currentTokenType () + "; cursor is just before this comment: " + cursor.xmlText () ; */ break ; case TokenType.INT_PROCINST: /*response = cursor.currentTokenType () + "; cursor is just before this processing instruction: " + cursor.xmlText () ; */ break ; case TokenType.INT_END: /*response = cursor.currentTokenType () + "; cursor is just before the token representing an element's end." ; */ break ; case TokenType.INT_ENDDOC: /*response = cursor.currentTokenType () + "; cursor is at the end of the XML." ; */ break ; case TokenType.INT_NONE: /*response = cursor.currentTokenType () + "; cursor is not at any recognizable token; it's just before: \n " + cursor.xmlText ( options ) ; */ break ; default : //response = "Yo! Something funky happened!" ; } /* Return the response string. */ return response; }
wanted to fetch ONLY 42.4351 which is the value of sf:ConversionRate and store it in double variable.. Thats all my requirement.
Anyone knows how to do this using com.bea.xml.XmlObject api methods?