0

これは、JabberServerからanwserを取得することからの新しい質問です。

受け取ったXMLをファイルのように考えると、うまくいきません。これは、予期しないファイルの終わりが発生したエラーの原因です。XMLを段階的に解析する必要があります。

わかりました、私の質問はどうですか?閉じていないxmlのpiceを送信するにはどうすればよいですか?

オブジェクトをシリアル化してから送信する必要がありますか?

ところで。Windows Phone 7.5にはないため、既存のライブラリを使用できません。

4

2 に答える 2

2

Let me elaborate on the explanation with an example (with snippets taken from here).

You're not going to be successful thinking of the XML you receive like a file, which is where your Unexpected end of file has occurred error is coming from. You must parse the XML incrementally.

When you connect to an XMPP, you open a connection to the server. To do this, you send something like the following...

<stream:stream
  to='example.com'
  xmlns='jabber:client'
  xmlns:stream='http://etherx.jabber.org/streams'
  version='1.0'>

...let's ignore authentication for the moment and just assume that this works. You'll notice that this one section alone is not valid XML (the element is not closed). However, for XMPP, that's okay. The server will send back it's own messages to tell you that you're good to go. Now we know that we can send our message stanzas. We type out our message, then send...

<message from='juliet@example.com' to='romeo@example.net'>
    <body>Romeo, romeo...</body>
</message>

After a few seconds, we decide to go offline...

    <presence type='unavailable'/>
</stream:stream>

Now let's look at what we sent...

<stream:stream
      to='example.com'
      xmlns='jabber:client'
      xmlns:stream='http://etherx.jabber.org/streams'
      version='1.0'>

    <!-- A few seconds elapsed -->

    <message from='juliet@example.com' to='romeo@example.net'>
        <body>Romeo, romeo...</body>
    </message>

    <!-- A few seconds elapsed -->

    <presence type='unavailable'/>
</stream:stream>

So, in the end, you can think of the interaction with the server as if you are creating a document that EVENTUALLY becomes a fully valid XML document. And this is a nice way to think about things when you're first learning about XMPP.

However, you're creating this document over a period of time, not all at once. XML libraries typically don't think that you're only going to create PART of the document now: they're concerned with creating the entire document at once. This is why traditional XML libraries may not be helpful for you in writing XMPP programs. Additionally, a simple XML library won't be able to deal with extra information such as authentication logic.

In the end, you COULD write your own library. However, you would need to be very careful in your selection of tools (as like I said before, XML libraries might not be able to handle these partial XML creations).

Anyway, in the end, your question is...

How can I send not closed pice of xml?

And the answer is: find a library to do it for you. And I don't mean just the XML parts: I mean all of XMPP. The right library will not even need you to concern yourself with the fact that XML even exists unless you get really advanced. If you can't find a library...

  1. Look harder. Spending a day looking for a library is STILL less time than a month making your own.
  2. See if you can find an open-source library that does most of what you want. Then, work around the parts that are different, or make your own source code changes to fill in the gaps.
于 2012-08-15T00:15:46.020 に答える
0

XMPPプロトコルはXMLコードに基づいています。基本的にはこれまでです。サーバーとの接続は開始タグを使用して行われ、認証後よりも多くのXMLメッセージがサーバーとの間で送受信されます。これはスタンザと呼ばれます。サーバーでの作業が終了すると、XML「ファイル」は終了タグで閉じられます。。次に、サーバーはソケットを閉じます。そのため、「ファイル」を閉じずにXMLコードを送信できます。これがあなたの理解に役立つことを願っています。

于 2012-08-14T23:33:18.063 に答える