Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Page:  1  2  next
Avatar
lingx825 #1
Member since Nov 2007 · 23 posts
Group memberships: Members
Show profile · Link to this post
Subject: About complicate custom packet like vCard
Hi,when I try to create my own iq, it can send to the server well,
but the response iq stream from server contains blank and "\n" somewhere,
I try to get my own query class and its subclass from the xml stream,
I use
get { return SelectSingleElement(typeof(myClass)) as myClass; }
just like vcard did,but it return null, i can see its "base" contain the myClass's content
Is it the blank and "\n" issue? Or some other reasons?
How to make it work? Thanks for any advice

PS:I add the code
ElementFactory.AddElementType("mytag","mynamespace", typeof(myclass));
in my program not in the agsXMPP.Factory.ElementFactory,
But I think when the program run to my "AddElementType()",it would call the ElementFactory's static constructor,
so no matter where my "AddElementType()" put should always work fine,right?
This post was edited 2 times, last on 2007-12-07, 03:53 by lingx825.
Avatar
lingx825 #2
Member since Nov 2007 · 23 posts
Group memberships: Members
Show profile · Link to this post
BTW: is there a simply way let the program read the xml content from local file?
so I don't need to connect to the server everytime,thank you~
Avatar
lingx825 #3
Member since Nov 2007 · 23 posts
Group memberships: Members
Show profile · Link to this post
Hi,when I debug the program serveral time,finally I found that this is not the blank and "\n" issue,I add a test code
 
Element temp= SelectSingleElement("mytag");
then I get the xml content,but when use
SelectSingleElement(typeof(myClass));
seems doesn't work,then I test the temp's type
temp.GetType()==typeof(myClass)
it return false,so this may be the problem,does it because the xml content contains a list of same tag not declare in myClass?
I use the getList() method to get these same tag,like the vCard do,
it also have GetAddresses(), GetEmailAddresses(),GetTelephoneNumbers() to get the list of same tag
and I don't find any declare about address,email,tel in vCard,did I miss something?
why the agsXMPP.protocol.client.iq can use
return this.SelectSingleElement("vCard") as Vcard;
but I can't?Please help~
Avatar
lingx825 #4
Member since Nov 2007 · 23 posts
Group memberships: Members
Show profile · Link to this post
I'm confused,I did a simple test,write a testelement class inherit the Element,register in the elementFactory
and use a Elment object e contain the xml as testelement define and contains " " and "\n"
but I can't convert e to testelement,why?
This post was edited 2 times, last on 2007-12-07, 05:45 by lingx825.
Avatar
Jabberer #5
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #1
Quote by lingx825:
Hi,when I try to create my own iq, it can send to the server well,
but the response iq stream from server contains blank and "\n" somewhere,
I try to get my own query class and its subclass from the xml stream, ...

you should derive your custom packets from Element.
Did you read this manual about for custom packets?
http://www.ag-software.net/download/xmpp/creating_own_pack…
Software Developer
AG-Software
Avatar
Jabberer #6
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #2
Quote by lingx825:
BTW: is there a simply way let the program read the xml content from local file?
so I don't need to connect to the server everytime,thank you~

Yes, here is a code snippet from Mini Client and how MiniClient loads its settings.

  1. private void LoadSettings()
  2. {
  3.     if (System.IO.File.Exists(SettingsFilename))
  4.     {
  5.         Document doc = new Document();
  6.         doc.LoadFile(SettingsFilename);
  7.         Element Login = doc.RootElement.SelectSingleElement("Login");
  8.  
  9.         txtJid.Text = Login.GetTag("Jid");
  10.         txtPassword.Text = Login.GetTag("Password");
  11.         txtResource.Text = Login.GetTag("Resource");
  12.         numPriority.Value = Login.GetTagInt("Priority");
  13.         chkSSL.Checked = Login.GetTagBool("Ssl");
  14.     }
  15. }
Software Developer
AG-Software
Avatar
Jabberer #7
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #3
Quote by lingx825:
Hi,when I debug the program serveral time,finally I found that this is not the blank and "\n" issue,I add a test code
 
Element temp= SelectSingleElement("mytag");
then I get the xml content,but when use
SelectSingleElement(typeof(myClass));
seems doesn't work,then I test the temp's type
temp.GetType()==typeof(myClass)
it return false,so this may be the problem,does it because the xml content contains a list of same tag not declare in myClass?
I use the getList() method to get these same tag,like the vCard do,
it also have GetAddresses(), GetEmailAddresses(),GetTelephoneNumbers() to get the list of same tag
and I don't find any declare about address,email,tel in vCard,did I miss something?
why the agsXMPP.protocol.client.iq can use
return this.SelectSingleElement("vCard") as Vcard;
but I can't?Please help~

When you class is registered correctly in the lementFactory then it returns your type.
If it doesnt then i assume that there is a problem with registering your packet in the ElementFactory
Software Developer
AG-Software
Avatar
lingx825 #8
Member since Nov 2007 · 23 posts
Group memberships: Members
Show profile · Link to this post
Thanks for your answer,now I can get the top one of my class regiter in ElementFactory
But I can get it's subclass , I regiter the subclass the same namespace its superclass have
like the vCard do,its subclass have the same namespace too
AddElementType("vCard",                Uri.VCARD,                    typeof(agsXMPP.protocol.iq.vcard.Vcard));
            AddElementType("TEL",                Uri.VCARD,                    typeof(agsXMPP.protocol.iq.vcard.Telephone));
            AddElementType("ORG",                Uri.VCARD,                    typeof(agsXMPP.protocol.iq.vcard.Organization));
            AddElementType("N",                    Uri.VCARD,                    typeof(agsXMPP.protocol.iq.vcard.Name));
            AddElementType("EMAIL",                Uri.VCARD,                    typeof(agsXMPP.protocol.iq.vcard.Email));           
            AddElementType("ADR",                Uri.VCARD,                    typeof(agsXMPP.protocol.iq.vcard.Address));
Here's my code
ElementFactory.AddElementType(IESTagName.IESQuery,                       IESTagName.IESNameSpace, typeof(IESQuery));
ElementFactory.AddElementType(IESTagName.IESCommandBean,            IESTagName.IESNameSpace, typeof(IESCommandBean));
ElementFactory.AddElementType(IESTagName.CommandBaseBean,          IESTagName.IESNameSpace, typeof(IESCommandBaseBean));
ElementFactory.AddElementType(IESTagName.Question,                         IESTagName.IESNameSpace,      typeof(Question));
ElementFactory.AddElementType(IESTagName.Answer,                             IESTagName.IESNameSpace,      typeof(Answer));
ElementFactory.AddElementType(IESTagName.PersonalSetting,                 IESTagName.IESNameSpace,  ypeof(PersonalSetting));
ElementFactory.AddElementType(IESTagName.PointRecord,                        IESTagName.IESNameSpace,    typeof(PointRecord));
ElementFactory.AddElementType(IESTagName.Message,                      IESTagName.IESNameSpace, typeof(ClientUI.ies.commandbean.Message));
Here's the class structure
IESIQ:IQ                               //class contain IESQuery
IESQuery:Element                   //class contain IESCommandBean
IESCommandBean:Element       //class contain IESCommandBaseBean,Question,PersonalSetting,etc
IESCommandBaseBean:Element//class contain a string attribute commandName
Question:Element                  //class contain some string attributes,it don't have Answer arrtibute,but the server will response            
                                            serveral <answer> in <question>,so I write a getAnswerList() to get the answer list
Answer:Element                    // class contain some string attributes
PersonalSetting:Element         //class contain some string attributes ,it don't have PointRecord attribute,but the server will
                                          response serveral <pointrecord> in <personal>,so I write a getPointList() to get the answer list
PointRecord:Element              //class contain some string attributes

I have a question,If in a class don't declare some tag(like my Question don't declare answer,my PersonalSetting don't declare PointRecord,but my program will recieve <answer> in <question> and <pointrecord> in <personal>),can they transfer to the class Question/PersonalSetting?Do the transition only relative to the tagname and namespace?or it also relative to the sub tag?
Furthermore,where I can find the code in agsXMPP that change the XML stream to a class?

now in XmppCon_OnIq(object sender, agsXMPP.protocol.client.IQ iq),I can get the IESQuery form iq,but I can't get others,I don't know why,I'm still debugging and have no idea about the problem..
This post was edited 3 times, last on 2007-12-07, 09:44 by lingx825.
Avatar
lingx825 #9
Member since Nov 2007 · 23 posts
Group memberships: Members
Show profile · Link to this post
Hi,I try a new test,make another console program
copy the ElementFactory code,and read the same xml content from a local file
And finally I can get my own Type form Element,so the ElementFactory code definitely right
This is exciting,but I'm still stuck in my real program, Can anybody tell me why?
It's just like a trap,Just not let me out,Pls Help,Realy Thank YOU~
This post was edited on 2007-12-07, 11:04 by lingx825.
Avatar
Alex #10
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
sorry, but we really can't help with only this small code snippets.
You have to understand the complete logic and hierarchy of our Xml logic.

Please post the generated XML of your packets and let us know what the value of IESTagName.IESNameSpace is.

Alex
Avatar
lingx825 #11
Member since Nov 2007 · 23 posts
Group memberships: Members
Show profile · Link to this post
Hello,Alex
I write a method the get the XML content

private void XmppCon_OnWriteXml(object sender, string xml)
{
            System.Console.WriteLine("------START SEND-------------------");
            System.Console.WriteLine("send:" + xml);
            System.Console.WriteLine("-------END SEND------------------");
}
And here's the output
-------START RECEIVE------------------
receive:<iq xmlns="jabber:client" to="abc@roger/agsXMPP" type="result" id="agsXMPP_3"><query xmlns="botwave:token"><IESCommandJavaBean>
    <commandBaseBean>
        <commandName>ies.getquestionlist</commandName>
    </commandBaseBean>
    <page>
        <pageNum>1</pageNum>
        <pageSize>10</pageSize>
        <recordCount>48</recordCount>
    </page>
    <question>
        <content>??????????</content>
        <qid>1</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:45:18</time>
        <title>?????</title>
    </question>
    <question>
        <content>?????????</content>
        <qid>2</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:50:41</time>
        <title>??????</title>
    </question>
    <question>
        <content>????????</content>
        <qid>3</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:51:54</time>
        <title>?????</title>
    </question>
    <question>
        <content>????????????</content>
        <qid>4</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:53:07</time>
        <title>???????</title>
    </question>
    <question>
 <content>???????????????????...</content>
        <qid>5</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:54:42</time>
        <title>???????????</title>
    </question>
    <question>
        <content>?????????????3?????...</content>
        <qid>6</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:55:26</time>
        <title>?????“3”</title>
    </question>
    <question>
        <content>????????2??“2”?“2”????...</content>
        <qid>7</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:55:55</time>
        <title>?????“2”</title>
    </question>
    <question>
        <content>“1”?????????????????...</content>
        <qid>8</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:56:24</time>
        <title>?????“1”</title>
    </question>
    <question>
        <content>?????????????????????...</content>
        <qid>9</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:56:52</time>
        <title>????-----???????</title>
    </question>
    <question>
        <content>???????????????????...</content>
        <qid>10</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:57:14</time>
        <title>?????????</title>
    </question>
</IESCommandJavaBean></query></iq>
--------END RECEIVE-----------------
I copy this content into my local file content.xml
and try the test code,the ElementFactory.AddElementType() was copy from my real program

static void Main()
{
            ElementFactory.AddElementType(IESTagName.IESQuery, IESTagName.IESNameSpace, typeof(IESQuery));
            ElementFactory.AddElementType(IESTagName.IESCommandBean, IESTagName.IESNameSpace, typeof(IESCommandBean));
            ElementFactory.AddElementType(IESTagName.CommandBaseBean, IESTagName.IESNameSpace, typeof(IESCommandBaseBean));
            ElementFactory.AddElementType(IESTagName.Question, IESTagName.IESNameSpace, typeof(Question));
            ElementFactory.AddElementType(IESTagName.Answer, IESTagName.IESNameSpace, typeof(Answer));
            ElementFactory.AddElementType(IESTagName.PersonalSetting, IESTagName.IESNameSpace, typeof(PersonalSetting));
            ElementFactory.AddElementType(IESTagName.PointRecord, IESTagName.IESNameSpace, typeof(PointRecord));
            ElementFactory.AddElementType(IESTagName.Message, IESTagName.IESNameSpace, typeof(ClientUI.ies.commandbean.Message));
            ElementFactory.AddElementType(IESTagName.Page, IESTagName.IESNameSpace, typeof(Page));
           
 Document doc = new Document();
               doc.LoadFile(@"c:\content.xml");

               //Element iq = doc.RootElement.SelectSingleElement("iq",true);
               IQ iq = doc.RootElement as IQ;

               IESQuery query = iq.SelectSingleElement(typeof(IESQuery)) as IESQuery;
               IESCommandBean commandbean = iq.SelectSingleElement(typeof(IESCommandBean), true) as IESCommandBean;
               Question question = iq.SelectSingleElement(typeof(Question), true) as Question;
               IESCommandBaseBean basebean = commandbean.BaseBean;
               Page page = iq.SelectSingleElement(typeof(Page),true) as Page;
               ElementList el = commandbean.SelectElements(typeof(Question));
               ArrayList qlist = new ArrayList();
               foreach (Question q in el) {qlist.Add(q);}
}
the code work really fine, the query,commandbean,question,basebean,page even the qlist get their own value,so I think there should no problem in ElementFactory~

But in my real program

void  XmppCon_OnIq(object sender, agsXMPP.protocol.client.IQ iq)
        {
             if (iq.Query.GetType() == typeof(IESQuery))
                    {
                        IESQuery query = iq.SelectSingleElement(typeof(IESQuery)) as IESQuery;
                        IESCommandBean commandbean = iq.SelectSingleElement(typeof(IESCommandBean),true) as IESCommandBean;
                        Question question = iq.SelectSingleElement(typeof(Question),true) as Question;
                        IESCommandBaseBean basebean = commandbean.BaseBean;
                      
                        switch (basebean.CommandName)
                                 .
                                 .
                                 .
They are almost the same as the test code,but only the [IESQuery query] get its value,the commandbean,question,basebean are null, I have no idea why this happen~
Avatar
lingx825 #12
Member since Nov 2007 · 23 posts
Group memberships: Members
Show profile · Link to this post
Sorry,there are many chinese words show as ?????????
Does it matter for the program?But the test code work fine
BTW: I use the code button to surround my code,why they don't show the line number?
This post was edited 2 times, last on 2007-12-07, 13:19 by lingx825.
Avatar
Jabberer #13
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
can you also post the debug of the receiving client?

  1. void  XmppCon_OnIq(object sender, agsXMPP.protocol.client.IQ iq)
  2. {
  3.    Console.WriteLine(iq.ToString(Formatting.Indented));
  4.    
  5.    // your code ...
  6. }

To make sure that nothing gets lots or rewritten on your server.
Software Developer
AG-Software
Avatar
lingx825 #14
Member since Nov 2007 · 23 posts
Group memberships: Members
Show profile · Link to this post
Hi,Jabberer
I add the code as you said
void  XmppCon_OnIq(object sender, agsXMPP.protocol.client.IQ iq)
        {
            Console.WriteLine("##################  ON  IQ  #################");
            Console.WriteLine(iq.ToString(Formatting.Indented));
            Console.WriteLine("##################  ON  IQ  #################");
            
             if (iq.Query.GetType() == typeof(IESQuery))
                    {
                             Console.WriteLine("---------------On IESQuery-------------------------");
                             Console.WriteLine(iq.ToString(Formatting.Indented));
                             Console.WriteLine("---------------On IESQuery-------------------------");
and here is the output:

---------------On IESQuery-------------------------
<iq xmlns="jabber:client" to="abc@roger/agsXMPP" type="result" id="agsXMPP_3">
   <query xmlns="botwave:token">
      <IESCommandJavaBean>
    <commandBaseBean>
        <commandName>ies.getquestionlist</commandName>
    </commandBaseBean>
    <page>
        <pageNum>1</pageNum>
        <pageSize>10</pageSize>
        <recordCount>48</recordCount>
    </page>
    <question>
        <content>??????????</content>
        <qid>1</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:45:18</time>
        <title>?????</title>
    </question>
    <question>
        <content>?????????</content>
        <qid>2</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:50:41</time>
        <title>??????</title>
    </question>
    <question>
        <content>????????</content>
        <qid>3</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:51:54</time>
        <title>?????</title>
    </question>
    <question>
        <content>????????????</content>
        <qid>4</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:53:07</time>
        <title>???????</title>
    </question>
    <question>
        <content>???????????????????...</content>
        <qid>5</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:54:42</time>
        <title>???????????</title>
    </question>
    <question>
        <content>?????????????3?????...</content>
        <qid>6</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:55:26</time>
        <title>?????“3”</title>
    </question>
    <question>
        <content>????????2??“2”?“2”????...</content>
        <qid>7</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:55:55</time>
        <title>?????“2”</title>
    </question>
    <question>
        <content>“1”?????????????????...</content>
        <qid>8</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:56:24</time>
        <title>?????“1”</title>
    </question>
    <question>
        <content>?????????????????????...</content>
        <qid>9</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:56:52</time>
        <title>????-----???????</title>
    </question>
    <question>
        <content>???????????????????...</content>
        <qid>10</qid>
        <questioner>abc</questioner>
        <status>???</status>
        <time>2007-12-05 17:57:14</time>
        <title>?????????</title>
    </question>
</IESCommandJavaBean>
   </query>
</iq>
---------------On IESQuery-------------------------
It seems fine
This post was edited on 2007-12-07, 13:48 by lingx825.
Avatar
lingx825 #15
Member since Nov 2007 · 23 posts
Group memberships: Members
Show profile · Link to this post
Sometime there will be some agsXMPP.Xml.xpnet.PartialCharException,agsXMPP.Xml.xpnet.PartialTokenException,
But not happen in  XmppCon_OnIq(object sender, agsXMPP.protocol.client.IQ iq) Does it influence?

I need to go home,I will check the post next week,Thank you very much~
This post was edited on 2007-12-07, 14:13 by lingx825.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Page:  1  2  next
Forum: agsXMPP RSS