Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6739007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:26:11+00:00 2026-05-26T11:26:11+00:00

I have a legacy HTTP/XML service that I need to interact with for various

  • 0

I have a legacy HTTP/XML service that I need to interact with for various features in my application.

I have to create a wide range of request messages for the service, so to avoid a lot of magic strings littered around the code, I’ve decided to create xml XElement fragments to create a rudimentary DSL.

For example.

Instead of…

new XElement("root", 
  new XElement("request",
    new XElement("messageData", ...)));

I’m intended to use:

Root( Request( MessageData(...) ) );

With Root, Request and MessageData (of course, these are for illustrative purposes) defined as static methods which all do something similar to:

private static XElement Root(params object[] content) 
{
    return new XElement("root", content);
}

This gives me a pseudo functional composition style, which I like for this sort of task.

My ultimate question is really one of sanity / best practices, so it’s probably too subjective, however I’d appreciate the opportunity to get some feedback regardless.

  1. I’m intending to move these private methods over to public static class, so that they are easily accessible for any class that wants to compose a message for the service.

  2. I’m also intending to have different features of the service have their messages created by specific message building classes, for improved maintainability.

Is this a good way to implement this simple DSL, or am I missing some special sauce that will let me do this better?

The thing that leads me to doubt, is the fact that as soon as I move these methods to another class I increase the length of these method calls (of course I do still retain the initial goal of removing the large volume magic strings.) Should I be more concerned about the size (loc) of the DSL language class, than I am about syntax brevity?

Caveats

Note that in this instance the remote service poorly implemented, and doesn’t conform to any general messaging standards, e.g. WSDL, SOAP, XML/RPC, WCF etc.

In those cases, it would obviously not be wise to create hand built messages.

In the rare cases where you do have to deal with a service like the one in question here, and it cannot be re-engineered for whatever reason, the answers below provide some possible ways of dealing with the situation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:26:12+00:00Added an answer on May 26, 2026 at 11:26 am

    I noticed this article for constructing arbitrary XML with C#4.0 which is great.

    The source for the library is here – https://github.com/mmonteleone/DynamicBuilder/tree/master/src/DynamicBuilder

    At this time, there is a notable deficiency, no xml namespace support. Hopefully that will get fixed though.

    As a quick example, here’s how it’s done.

    dynamic x = new Xml();
    x.hello("world");
    

    Which yields:

    <hello>world</hello>
    

    Here’s another quick example yanked from the article.

    dynamic x = new Xml();
    
    // passing an anonymous delegate creates a nested context
    x.user(Xml.Fragment(u => {
        u.firstname("John");
        u.lastname("Doe");
        u.email("jdoe@example.org");
        u.phone(new { type="cell" }, "(985) 555-1234");
    }));
    

    Which yields:

    <user>
        <firstname>John</firstname>
        <lastname>Doe</lastname>
        <email>jdoe@example.org</email>
        <phone type="cell">(985) 555-1234</phone>
    </user>
    

    Having used the Ruby library Builder this method of creating arbitrary XML is similarly terse, to the point that it verges on “fun”!

    I’ve marked this as the answer, because, even though it doesn’t directly speak to “using a DSL to create arbitrary XML” it tends to remove the need due to the extremely terse and dynamic nature of the syntax.

    Personally I think this is the best way to create arbitrary XML in C# if you have the v4.0 compiler and have to crank it by hand, there are of course much better ways to generate XML automatically with serialization. Reserve this for XML which must be in a specific form for legacy systems only.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SOAP web service that is defined contract-first--the request and response xml
Sadly, I have a legacy PHP4 system that I continuously need to add features
I have a legacy VB6 application that was built using MSDE. As many client's
I have a legacy application that, at some point, generates the following code in
I have a legacy Rails 2.3.8 app I need to support and create an
I have a legacy app(HTTP and raw TCP) that uses traditional BIO (blocking IO)
We have an legacy application (mixture of classic ASP and ASP.net) that has a
I have legacy DB that store dates that means no-date as 9999-21-31, The column
I have a legacy C++ module that offers encryption/decryption using the openssl library (DES
We have some legacy code that needs to identify in the Page_Load which event

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.