Re: how to use XML parser
OnStartElement you will have found the tag name for example: "<tag>"
use something like [QUOTE] iTag = aElement.LocalName().DesC().AllocL();[/QUOTE]
In OnContentL, the aBytes will contain the corresponding data to the tag above.
Use debugger effectively here to see what each one is, but the broad idea is what I explained above.
Re: how to use XML parser
It is 1st time I am doing xml parsing myself,
I am in doubt if I am using the right approach
My code looks like this
void CXmlHandler::OnStartElementL( const RTagInfo &aElement, const RAttributeArray &aAttributes,
TInt aErrorCode )
{
if ( KErrNone == aErrorCode )
{
TBuf8<50>b(*(aElement.LocalName().DesC().Alloc()));
iBuf=b;
}
else
{
//error
}
}
void CXmlHandler::OnEndElementL( const RTagInfo &aElement, TInt aErrorCode )
{
if ( KErrNone == aErrorCode )
{
TBuf8<50>b(*(aElement.LocalName().DesC().Alloc()));
iBuf=b;
iBuf;
// Do something if needed....
}
else
{
//error
}
}
void CXmlHandler::OnContentL( const TDesC8 &aBytes, TInt aErrorCode )
{
if ( KErrNone == aErrorCode )
{
if((!aBytes.Compare(_L8("\n")))||(!aBytes.Compare(_L8("\t"))))
return;
HBufC* buffer = HBufC::NewLC( aBytes.Length() + 4 );
TPtr bufferPtr( buffer->Des() );
bufferPtr.Copy( aBytes );
if(!iBuf.Compare(_L8("PhoneBook")))
{
}
if(!iBuf.Compare(_L8("name")))
{
bufferPtr.Append(_L("xyz")) ;
}
if(!iBuf.Compare(_L8("number")))
{
bufferPtr.Append(_L("000")) ;
}
gConsole = Console::NewL(KConsoleMessageDisplay,TSize(20,20));
CleanupStack::PushL(gConsole);
gConsole->Printf(*buffer);
gConsole->Getch();
CleanupStack::PopAndDestroy(gConsole);
CleanupStack::PopAndDestroy();
}
else
{
//error
}
}
and xml file is->
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PhoneBook time="11/10/2012 8:07:46 am">
SyncMl for PhoneBook
<name>
sandeep
</name>
<number>
9711879354
</number>
<name>
Tripathy
</name>
<number>
3433331
</number>
</PhoneBook>
Though my code works I have a doubt, it will not work with multiple heirarchy child elements
last time I saw a code in linux, that was using a structure of elements in the parsing code, but I am not using.
Hope to get some help writing a better code....
Any pointer to an xml code that is using the parsed xml files would be great.
Regards!
Re: how to use XML parser
AFAIK it should work for any standard XML file even having multiple hierarchy children.
I do not understand your further question..if its working what more do you want. The API provided does the job, and thats the way it needs to be implemented (Ofcourse the code could have been a little cleaner, but for thats your preference ;)
btw, when you post code, use code tags for better readability.
Re: how to use XML parser
1>I had earlier seen use of struct of elements in one of my previous projects,which was using XML Parser, that is why I was concerned.
2>I am not getting the attribute details like
time="11/10/2012 8:07:46 am"
in xml file line
<PhoneBook time="11/10/2012 8:07:46 am">
3>what is "code tags " that you mentioned and how to use them?
4> I am getting strings like "\t" and "\n" in OnContentL( const TDesC8 &aBytes, TInt aErrorCode )
why so? is it ok?
Re: how to use XML parser
[QUOTE=sandeepintg;904921]1>I had earlier seen use of struct of elements in one of my previous projects,which was using XML Parser, that is why I was concerned.
2>I am not getting the attribute details like
time="11/10/2012 8:07:46 am
in xml file line
PhoneBook time="11/10/2012 8:07:46 am
3>what is "code tags " that you mentioned and how to use them?
4> I am getting strings like "\t" and "\n" in OnContentL( const TDesC8 &aBytes, TInt aErrorCode )
why so? is it ok?[/QUOTE]
1. ok
2. If you see that is not wrapped by the tags, so you wouldnt get it via the parse (atleast I dont know if). Usually such things you can see by debugging line by line and see each tag/variable contents and adjust your code..That way you will see how its exactly handling the parsing
3. use [CODE] [ /CODE] without the space ofcourse which I put there between '[' and '/' This is also available in the tools above if you 'go' into advanced editor.
[CODE] Here you can put the code[/CODE]
4. Answer similar to second part of 2. Probably your xml file contains newlines, etc. Again here advise is, debug and you would see what is happening there.
Re: how to use XML parser
It has been some time ago, but I had an XML example in the past, and now you can access it via [url]http://folk.uio.no/gergelyc/Symbian[/url] - it may help a little, at least it is a complete one.
Re: how to use XML parser
[QUOTE]2>I am not getting the attribute details like
time="11/10/2012 8:07:46 am"
in xml file line
<PhoneBook time="11/10/2012 8:07:46 am">[/QUOTE]
Basically RAttributeArray (Check OnStartElementL method) is a array of RAttribute which contain element name(here "time") and its value (here "11/10/2012 8:07:46 am"). In case you have more then one attribute in tag then just run a loop and get value of each item from RAttributeArray .