-
Reg:parsing
Hi actually im facing a problem in parsing my soap response... my application is getting crashed...im trying to parse the following xml content,
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ImportIncomingSMSResponse xmlns="http://www.atom8itsolutions.com/">
<ImportIncomingSMSResult>string</ImportIncomingSMSResult>
</ImportIncomingSMSResponse>
</soap:Body>
</soap:Envelope>
im using csendonfragement for parsing, but my application crashes in the line
reader->ParseL(fss, KToBeParsed);
for ur reference ill post my code below,
TBuf8<900> SMSText;
TBuf<20> inputtext1;
_LIT(KTxt2,"success");
inputtext1.Copy(KTxt2);
TBuf8<150> Text;
SMSText.Copy(_L("<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><ImportIncomingSMSResponse xmlns='http://www.atom8itsolutions.com/'><ImportIncomingSMSResult>"));
SMSText.Append( inputtext1);
Text.Copy(_L("</ImportIncomingSMSResult></ImportIncomingSMSResponse></soap:Body></soap:Envelope>"));
SMSText.Append(Text);
HBufC* buf16 = HBufC::NewLC(SMSText.Length());
buf16->Des().Copy(SMSText);
//CleanupStack::PopAndDestory(buf16);
// create new XML reader and push it to the cleanupstack
CSenXmlReader* reader = CSenXmlReader::NewL();
CleanupStack::PushL(reader);
//create a CSenDomFragment
CSenDomFragment* pBase = CSenDomFragment::NewL();
CleanupStack::PushL(pBase);
//the XML document to be parsed
_LIT(KToBeParsed, "buf16");
// TBuf8<160> SMSText;
// SMSText.Copy(_L("<messages><message><from>some number</from><content>some content</content></message><message><from>some number</from><content>some content</content></message></messages>"));
//_LIT(KToBeParsed, "SMSText");
//open a filesession
RFs fss;
User::LeaveIfError(fss.Connect());
CleanupClosePushL(fss);
//must set the content handler
reader->SetContentHandler(*pBase);
// and the reader
pBase->SetReader(*reader);
//do the parsing
reader->ParseL(fss, KToBeParsed);
//after the parsing, get the elements:
RPointerArray<CSenElement>& array = pBase->AsElement().ElementsL();
//start the listing of the elements, first level is 1
ListNodesL(array,1);
CleanupStack::PopAndDestroy(3); // pBase, fss, reader
// return retVal;
}
// The listing of the elements is done in ListNodesL function:
void CSmsHandler :: ListNodesL(RPointerArray <CSenElement>& aArray,
int aLevel)
{
_LIT(KNewLine, "\n");
_LIT(KNoContent,"NO CONTENT");
_LIT(KDepthFormatString, "lev%d: ");
int j=0;
TBuf<150> pNumber;
TBuf<150> pMessage;
TInt size = aArray.Count();
for(TInt i=0; i<size; i++)
{
//get an element
CSenElement* pElement = aArray[i];
TBool hasActualContent = EFalse;
if( pElement->HasContent() )
{
//get the content of the element
TPtrC8 content = pElement->Content();
//to a HBufC, notice "LC"
HBufC *pContent = SenXmlUtils::ToUnicodeLC(content);
//print current depth (“level”)
//trim possible whitespace characters
pContent->Des().Trim();
//if there is content after the trimming
if( pContent->Length() > 0)
{
hasActualContent = ETrue;
// aConsole.Printf(*pContent);
RDebug::Print(*pContent);
if(j==0)
{
//_LIT(KTxt1,*pContent);
pNumber.Copy(*pContent);
j++;
}
else
{
// _LIT(Msg,*pContent);
//TBuf<150> pMessage;
pMessage.Copy(*pContent);
j++;
}
}
//destroy pContent
CleanupStack::PopAndDestroy(pContent);
}
if( !hasActualContent)
{
// aConsole.Printf(KNoContent);
}
//get the first child
CSenElement* child = pElement->Child(1);
RDebug::Print( _L("RDebug Hello") );
//check if element has childs
if( child )
{
//get the child elements
RPointerArray<CSenElement>& tree = pElement->ElementsL();
//list child elements by a recursive call
ListNodesL(tree, ++aLevel);
}
aLevel--;
if (j>1 && j<3)
{
this->SendSmsL(pNumber,pMessage);
j=0;
}
else if(j>=3)
{
break;
}
}
// this->SendL(pNumber,pMessage);
} //for loop ends
can any one tell me a reason y my application crashes.... :( waiting for ur replies
-
Re: Reg:parsing
but have you tried which panic and on which line it is crashing ?
-
Re: Reg:parsing
[QUOTE=skumar_rao;764429]but have you tried which panic and on which line it is crashing ?[/QUOTE]
Hi kumar thanks for ur replies but i have mentioned the line...this is the line getting crashed,
reader->ParseL(fss, KToBeParsed);
panic is system error(-12) ........ :(
-
Re: Reg:parsing
It is not able to find xml tags properly .. consider refering to xml parsing code in wiki.
-
Re: Reg:parsing
Hi kumar i think its searching for a folder in the emulator,
_LIT(KToBeParsed, "buf16");
actually im trying to parse it directly i don want to create a file in my phone and after tat i should parse...it should be done directly... :(
-
Re: Reg:parsing
[QUOTE=skumar_rao;764431]It is not able to find xml tags properly .. consider refering to xml parsing code in wiki.[/QUOTE]
KErrPathNotFound -12 Unable to find the specified folder
actually i got this in symbian error codes... :(
-
Re: Reg:parsing
Do you have [b]any[/b] idea about what you are doing? [B]buf16 is a variable[/B] of yours, and you are putting its [b]name into a string[/b], and pass it as a [b]filename[/b] to that ParseL method.
How the hell is it supposed to work?
There are two ParseL methods in CSenXmlReader, use the other one, it can directly accept your SMSText, without conversion and without additional RFs.
-
Re: Reg:parsing
[QUOTE=wizard_hu_;764454]Do you have [b]any[/b] idea about what you are doing? [B]buf16 is a variable[/B] of yours, and you are putting its [b]name into a string[/b], and pass it as a [b]filename[/b] to that ParseL method.
How the hell is it supposed to work?
There are two ParseL methods in CSenXmlReader, use the other one, it can directly accept your SMSText, without conversion and without additional RFs.[/QUOTE]
Actually wizars i tried tat parsing first itself but, the xml is not getting parsed, the program executes fully no errors or panic shown....for ur referance ill show u the parsing code i used before....
//first the message is parsed
CSenXmlReader *pXmlReader = CSenXmlReader::NewL();
CleanupStack::PushL(pXmlReader);
CSenSoapMessage* pMessage = CSenSoapMessage::NewL();
CleanupStack::PushL(pMessage);
pMessage->SetReader(*pXmlReader);
TRAPD(leaveCode, pMessage->ParseL(KSOAPMessage));
if(leaveCode!=KErrNone)
{
CleanupStack::PopAndDestroy(2); //pMessage, pXmlReader
return;
}
//if there is a complete envelope then there are actual elements
TInt elements = pMessage->AsElement().ElementsL().Count();
if( elements > 0 )
{
//aConsole.Printf(_L("Got complete SOAP envelope\n"));
ProcessReceivedCompleteSoapMsgL(*pMessage);
}
else //if not, then we have a detached SOAP body
{
// ProcessReceivedSoapMsgBodyL(KSOAPMessage, *pXmlReader);
}
CleanupStack::PopAndDestroy(2); //pMessage, pXmlReader
}
// The processing of the whole element starts by checking, if a security header
// was received. Next check reveals, whether the message is a SOAP Fault, which
// could be extracted from the SOAP Body.
void CSmsHandler:: ProcessReceivedCompleteSoapMsgL(CSenSoapMessage& aMessage)
{
//There’s no other way to check for security header
CSenElement& headers = aMessage.HeaderL(); //header element
ProcessSecurityHeaderFromHeader(headers);
//First check if there is a Fault
if(aMessage.IsFault())
{
//includes SOAPFault
// note: by calling aMessage.FaultL() the ownership would NOT be taken
// CSenSoapFault* pFault = aMessage.FaultL();
//By calling DetachFaultL() the ownership IS taken:
CSenSoapFault *pFault = aMessage.DetachFaultL();
CleanupStack::PushL(pFault);
if(pFault)
{
//Process the SOAP Fault
HBufC8* pFaultAsXml = pFault->AsXmlL();
CleanupStack::PushL(pFaultAsXml);
pFaultAsXml->Length();
TPtrC8 faultCode = pFault->FaultCode();
TPtrC8 faultString = pFault->FaultString();
TPtrC8 faultActor = pFault->FaultActor();
TPtrC8 detail = pFault->Detail();
//Do something with values of this SOAP Fault
CleanupStack::PopAndDestroy(); // pFaultAsXml
}
CleanupStack::PopAndDestroy();//pFault
}
//Next process the SOAP Body
MSenElement *pBody = aMessage.BodyL().AsElement();
HBufC* pUnicode = pBody->AsXmlUnicodeL();
//Do something with the Body
delete pUnicode;
}
the xml is not parsed if is there any mistakes plz help me out....ill try to avoid it here after.... thanks for any replies... :(
-
Re: Reg:parsing
is there any one plz help me out???? :(