Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

parsing different xml messages

2 views
Skip to first unread message

kak...@gmail.com

unread,
Jul 27, 2010, 6:17:36 AM7/27/10
to
Hello,
I receive the following different Xml Messages from a socket:

<p_control_message serverIP="server-2" xmlns="http://test.com/pt">

<cmdReply>

<sessionList>

<session>

<id>5a62ded</id>

<subscriberId>101</subscriberId>

<subscriberName>Angie</subscriberName>

<presence>online</presence>

<note/>

<ipAddress>Some IP</ipAddress>

</session>

</sessionList>

</cmdReply>

</p_control_message>


<p_control_message xmlns="http://test.com/pt">

<cmd>

<systemMessage serverId="50" type="CRITICAL">

<message>Server server-1 is going down for redeploy!</message>

</systemMessage>

</cmd>

</pttv_control_message>

Which is the best way to make a distinction between them so that every
time my app receives the one or the other, parse them correctly?

Thanks

Antonis K.

Stefan Behnel

unread,
Jul 27, 2010, 6:30:48 AM7/27/10
to pytho...@python.org
kak...@gmail.com, 27.07.2010 12:17:

> I receive the following different Xml Messages from a socket:

From a bare socket? TCP? UDP? Or what else?


> Which is the best way to make a distinction between them so that every
> time my app receives the one or the other, parse them correctly?

Use an application level protocol?

Stefan

kak...@gmail.com

unread,
Jul 27, 2010, 7:58:16 AM7/27/10
to

From a tcp socket using the twisted framework.
Application level protocol... Such as?

Stefan Behnel

unread,
Jul 27, 2010, 8:14:39 AM7/27/10
to pytho...@python.org
kak...@gmail.com, 27.07.2010 13:58:

> On Jul 27, 6:30 am, Stefan Behnel wrote:
>> kak...@gmail.com, 27.07.2010 12:17:
>>
>>> I receive the following different Xml Messages from a socket:
>>
>> From a bare socket? TCP? UDP? Or what else?
>>
>>> Which is the best way to make a distinction between them so that every
>>> time my app receives the one or the other, parse them correctly?
>>
>> Use an application level protocol?
>>
>> Stefan
>
>> From a tcp socket using the twisted framework.
>> Application level protocol... Such as?

Depends on what you *can* use. Do you control the sending side?

Note: giving better details helps others in giving better answers.

Stefan

kak...@gmail.com

unread,
Jul 27, 2010, 8:26:11 AM7/27/10
to

Well yes you are right!
I can't control the sending side.
The app i'm writing just accepts incoming xml messages. Like the ones
above.
When i receive a message I parse it and print the information.
I know how to parse both xml messages.
What i want is to distinguish them so that i can trigger the
appropriate parsing method.


A.K.

Stefan Behnel

unread,
Jul 27, 2010, 8:41:59 AM7/27/10
to pytho...@python.org
kak...@gmail.com, 27.07.2010 14:26:

> On Jul 27, 8:14 am, Stefan Behnel wrote:
>> kak...@gmail.com, 27.07.2010 13:58:
>>
>>> On Jul 27, 6:30 am, Stefan Behnel wrote:
>>>> kak...@gmail.com, 27.07.2010 12:17:
>>
>>>>> I receive the following different Xml Messages from a socket:
>>
>>>> From a bare socket? TCP? UDP? Or what else?
>>
>>>>> Which is the best way to make a distinction between them so that every
>>>>> time my app receives the one or the other, parse them correctly?
>>
>>>> Use an application level protocol?
>>
>>>> From a tcp socket using the twisted framework.
>>>> Application level protocol... Such as?
>>
>> Depends on what you *can* use. Do you control the sending side?
>>
>> Note: giving better details helps others in giving better answers.
>
> Well yes you are right!
> I can't control the sending side.
> The app i'm writing just accepts incoming xml messages. Like the ones
> above.
> When i receive a message I parse it and print the information.
> I know how to parse both xml messages.
> What i want is to distinguish them so that i can trigger the
> appropriate parsing method.

Do they come in concatenated or one per connection?

Stefan

kak...@gmail.com

unread,
Jul 27, 2010, 8:43:13 AM7/27/10
to

one per connection.

Stefan Behnel

unread,
Jul 27, 2010, 9:06:44 AM7/27/10
to pytho...@python.org
kak...@gmail.com, 27.07.2010 14:43:

Ah, ok, then just parse the message using (c)ElementTree and look at the
name of the first child below the root node (assuming that both messages
were supposed to have the same root node, as you may have wanted to
indicate in your original posting). A dict dispatch to a function or method
will do just fine.

Stefan

kak...@gmail.com

unread,
Jul 27, 2010, 9:10:53 AM7/27/10
to

ok that's great, thanks Stefan
i'll try it.

Antonis

0 new messages