how can i get data from xml with syexpat

Login to reply to this topic.
Mon, 2007-04-09 07:17
Joined: 2006-10-20
Forum posts: 26
--------------------------------------------------------------------------------

i am newbie to syexpat,i download todd's software syexpat,i can run its example, in the Elements example, the emulator display the result ln: test
and so on,
for example
<head>
<test1>mydata1</test1>
<test2>mydata2</test2>
<test3>mydata3</test3>
</head>

how can i get mydata1? if i only want to get mydata2, what shuold i do, in  the elements example the code(TSyExpatStatus status = reader->Parse(doc, ETrue); )doesnot display the content. i
i can't grasp the functions of syexpat now. can someone give me some code or a example?

Tue, 2007-04-10 15:27
Joined: 2007-04-10
Forum posts: 17
Re: how can i get data from xml with syexpat
In the StartElement method store the state, for example:

void StartElement(const TQualified& aName, const RArray<TAttribute>& attributes){
   if(aName.iLocalName.Compare(_L("test1"))){
      state = EStateT1;
   }
}

In the CharacterData method extract the data
voidCharacterData(const TDesC& aData) {
   if(state == EState1){
      myvar1 = aData.AllocL(); //will be mydata1
   }
}

Finally, reset the state in the EndElement method
void StartElement(const TQualified& aName){
   if(aName.iLocalName.Compare(_L("test1"))){
      state = EStateNone;
   }
}
Wed, 2007-04-11 02:45
Joined: 2006-10-20
Forum posts: 26
Re: how can i get data from xml with syexpat
thanx for your help.
i know the functions you said, but...
i dont know how to use the function, how to link the parameter of function to a tbuf, where is the data after running the function?

my example be store in a tbuf, how to get a tbuf that contains  the data i want.

can you give me some codes?
Wed, 2007-04-11 09:54
Joined: 2004-09-14
Forum posts: 140
Re: how can i get data from xml with syexpat
Hi,

If you look in th examples folder, there is a project called elements, this has a simple example on how to parse xml content.

You can also look at my blog on Forum Nokia

http://blogs.forum.nokia.com/view_entry.html?id=475

which has some more details

Paul Todd

Fri, 2007-05-11 13:29
Joined: 2007-04-10
Forum posts: 17
Re: how can i get data from xml with syexpat
You can envelope the XMLParser class. For example:

class XmlParserMosaic : public MSyDocHandler, MSyDeclHandler {

public:
    XmlParserMosaic();
    ~XmlParserMosaic();

    CMosaicImageArray *Parse(const TDesC8 &xml);
    TSyExpatStatus GetStatus() {return iStatus;}
    TSyExpatError GetLastError() {return iError;}

    // De MSyDocHandler
    void StartElement(const TQualified& aName, const RArray<TMyAttribute>& attributes);
    void EndElement(const TQualified& aName);
    void CharacterData(const TDesC& aData);
    void ProcessingInstruction(const TDesC& aTarget, const TDesC& aData);
    void Comment(const TDesC& aData);
    void StartCDataSection();
    void EndCDataSection();
    void Default(const TDesC& /*aData*/);
    void SetParser(CExpatParserBase* aParser);
...
    HBufC* GetMyvar();

private:
    HBUfC* myvar1
}
  • Login to reply to this topic.