Configurable XLinq Selection
-
Hi All, This is a hard one to describe, I am not looking for code here per se, rather a nice way of doing things. I am developing an XMPP server that uses XLinq (nice...). I am use a selection mechanism to call XML handlers for certain elements in the document as they arrive. For example: - When you get a node and it is the root node notify StreamHandler. - When you get a node an it is inside notify BindHandler The code currently looks like this, and is hard-coded into the component constructor.
// Create the selection that will always select the root <stream:stream> ElementSelection<SourceCode.BlackConduit.Server.ClientConnection> streamSelection = SelectionStream.Add(new ElementSelection<SourceCode.BlackConduit.Server.ClientConnection>( "stream", Uris.Streams)); streamSelection.AddHandler(new StreamHandler()); // Add the <bind> element which falls under the <stream:stream> // i.e <stream:stream xmlns:stream="..."><bind name="foo"/> streamSelection.Add(new ElementSelection<SourceCode.BlackConduit.Server.ClientConnection>( "bind", Uris.Component.Accept)) .AddHandler(new BindHandler(), e => e.HasAttribute("name"));
NB: StreamSelection.Add() returns the first parameter sent it to (allows for shorter code). Any thoughts on how I could make this either: - Configurable via the app.config or custom xml file. This would load plugin dlls. - Extendable (spelling?) via plugin dlls. And finally, any thoughts on how I could clean up the syntax? I will try and fly writing an article up on this (esp. the streaming XML reader that I wrote) past my employer, so hold thumbs :~. Thanks a ton!
He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb] Jonathan C Dickinson (C# Software Engineer)
-
Hi All, This is a hard one to describe, I am not looking for code here per se, rather a nice way of doing things. I am developing an XMPP server that uses XLinq (nice...). I am use a selection mechanism to call XML handlers for certain elements in the document as they arrive. For example: - When you get a node and it is the root node notify StreamHandler. - When you get a node an it is inside notify BindHandler The code currently looks like this, and is hard-coded into the component constructor.
// Create the selection that will always select the root <stream:stream> ElementSelection<SourceCode.BlackConduit.Server.ClientConnection> streamSelection = SelectionStream.Add(new ElementSelection<SourceCode.BlackConduit.Server.ClientConnection>( "stream", Uris.Streams)); streamSelection.AddHandler(new StreamHandler()); // Add the <bind> element which falls under the <stream:stream> // i.e <stream:stream xmlns:stream="..."><bind name="foo"/> streamSelection.Add(new ElementSelection<SourceCode.BlackConduit.Server.ClientConnection>( "bind", Uris.Component.Accept)) .AddHandler(new BindHandler(), e => e.HasAttribute("name"));
NB: StreamSelection.Add() returns the first parameter sent it to (allows for shorter code). Any thoughts on how I could make this either: - Configurable via the app.config or custom xml file. This would load plugin dlls. - Extendable (spelling?) via plugin dlls. And finally, any thoughts on how I could clean up the syntax? I will try and fly writing an article up on this (esp. the streaming XML reader that I wrote) past my employer, so hold thumbs :~. Thanks a ton!
He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb] Jonathan C Dickinson (C# Software Engineer)
Jonathan C Dickinson wrote:
I am developing an XMPP server that uses XLinq (nice...).
Although I never wrote the server bits, I wrote a fully fledged client for it. I used XML serialization quite successfully after fixing the spec's incorrectly defined schema's.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Jonathan C Dickinson wrote:
I am developing an XMPP server that uses XLinq (nice...).
Although I never wrote the server bits, I wrote a fully fledged client for it. I used XML serialization quite successfully after fixing the spec's incorrectly defined schema's.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)Very interesting, I never used the schemas. I have a few years experience with XMPP. I am going to use Serialization for the client bits (the code is already there). My initial version used serialization (the handlers basically reacted to types instead of elements), and after experimenting with pure XML I found it to be A LOT faster. You should tell the XMPP editor (Peter Saint-Andre) that the schemas are a-miss. Do you have a d/l link for the client, I would be interested in taking a look at the architecture for ideas.
He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb] Jonathan C Dickinson (C# Software Engineer)
-
Very interesting, I never used the schemas. I have a few years experience with XMPP. I am going to use Serialization for the client bits (the code is already there). My initial version used serialization (the handlers basically reacted to types instead of elements), and after experimenting with pure XML I found it to be A LOT faster. You should tell the XMPP editor (Peter Saint-Andre) that the schemas are a-miss. Do you have a d/l link for the client, I would be interested in taking a look at the architecture for ideas.
He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb] Jonathan C Dickinson (C# Software Engineer)
Jonathan C Dickinson wrote:
You should tell the XMPP editor (Peter Saint-Andre) that the schemas are a-miss.
This was about 4 years back :) I barely recall the spec, and I am sure it has changed or been updated since then.
Jonathan C Dickinson wrote:
Do you have a d/l link for the client, I would be interested in taking a look at the architecture for ideas.
It was for a commercial contract. Sorry. I could try and see if I have the schemas maybe that I used for type generation (lol, this was on .NET 1.0 still, partial classes would have been a blessing).
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Jonathan C Dickinson wrote:
You should tell the XMPP editor (Peter Saint-Andre) that the schemas are a-miss.
This was about 4 years back :) I barely recall the spec, and I am sure it has changed or been updated since then.
Jonathan C Dickinson wrote:
Do you have a d/l link for the client, I would be interested in taking a look at the architecture for ideas.
It was for a commercial contract. Sorry. I could try and see if I have the schemas maybe that I used for type generation (lol, this was on .NET 1.0 still, partial classes would have been a blessing).
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)Just out of interests sake, did you roll your own 'streamable' XML parser or did you use another method? My XML parser right now, as it seems, is rock-solid: but I can't really deny that there are other libraries out there that have been in the wild for longer (in my case, at all). One thing I tried was creating a special stream that used mutexes to present information to the .Net XML classes when it was ready, but the threading overhead was HUGE. Guess it's cool to find another XMPP guy on CP ;).
He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb] Jonathan C Dickinson (C# Software Engineer)
-
Just out of interests sake, did you roll your own 'streamable' XML parser or did you use another method? My XML parser right now, as it seems, is rock-solid: but I can't really deny that there are other libraries out there that have been in the wild for longer (in my case, at all). One thing I tried was creating a special stream that used mutexes to present information to the .Net XML classes when it was ready, but the threading overhead was HUGE. Guess it's cool to find another XMPP guy on CP ;).
He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb] Jonathan C Dickinson (C# Software Engineer)
Jonathan C Dickinson wrote:
Just out of interests sake, did you roll your own 'streamable' XML parser or did you use another method?
IIRC my client was reading an open ended XML document. As new elements came in, I would simply deserialize the XML into a class instance, and pass that object (which was derived from some base class like others) to a processing function, and handle the action there as well as any responses which was again in the form of object instances, that got serialized to XML and simply pumped back to the server. All in all, it was pretty elegant :)
Jonathan C Dickinson wrote:
One thing I tried was creating a special stream that used mutexes to present information to the .Net XML classes when it was ready, but the threading overhead was HUGE.
Like said, I never got into doing an XMPP server, I did do a simple server module (or whatever you call it), but that was just a slightly modified client. I will try dig up the code tonite, if I still have it, and refresh my memory a bit :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Jonathan C Dickinson wrote:
Just out of interests sake, did you roll your own 'streamable' XML parser or did you use another method?
IIRC my client was reading an open ended XML document. As new elements came in, I would simply deserialize the XML into a class instance, and pass that object (which was derived from some base class like others) to a processing function, and handle the action there as well as any responses which was again in the form of object instances, that got serialized to XML and simply pumped back to the server. All in all, it was pretty elegant :)
Jonathan C Dickinson wrote:
One thing I tried was creating a special stream that used mutexes to present information to the .Net XML classes when it was ready, but the threading overhead was HUGE.
Like said, I never got into doing an XMPP server, I did do a simple server module (or whatever you call it), but that was just a slightly modified client. I will try dig up the code tonite, if I still have it, and refresh my memory a bit :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)Ah, I see, so they created the reader capable of open ended XML documents. It is strange that this functionality isn't present in the .Net framework. The XSF is very aware of backward-compatibility, you should find it all works on the newest servers/libraries ;). Thanks for the input!
He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb] Jonathan C Dickinson (C# Software Engineer)