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

  • Home
  • SEARCH
  • 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 3355860
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:26:43+00:00 2026-05-18T02:26:43+00:00

This is a design question, to whet the guru’s appetite. In a previous version,

  • 0

This is a design question, to whet the guru’s appetite.

In a previous version, the code was using a path definition, i.e. /../../ to provide instructions on how to build artbitary xml documents. The documents had to be correct according to xml schema, so the path’s were essentially xpaths, being read and used in switch statements to call code to construct the doc. But don’t get hung up on it.

For example the call when read in and coded

jim.set("/Alert/Source/DetectTime", "12:03:2010 12:22:21");

would create

<Alert> 
  <Source>
    <DetectTime>12:03:2010 12:22:21</DetectTime>
  </Source>
</Alert>

The jim.set just stores the tree in a particular context.

Now I’d like to use linq to xsd, to create the xml tree, but i’m still looking for some contruct that will enable a user to define how the tree will be constructed. XPath’s are easy, but kinda bulky to implement, not elegant and I don’t easy mapping.

Any ideas, any programs, open source, research, anything would be apreciated. If I don’t get an answer I’ll offer a decent bounty in 3 days.
Bob.

  • 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-18T02:26:44+00:00Added an answer on May 18, 2026 at 2:26 am

    How about doing something like this:

    public XDocument CreateXDocument(string path, string value)
    {
        var parts = path.Split(new [] { '/', },
            StringSplitOptions.RemoveEmptyEntries);
        return new XDocument(this.CreateXElement(parts, value));
    }
    
    private XElement CreateXElement(IEnumerable<string> parts, string value)
    {
        var content = parts.Count() == 1 ?
            (object)value :
            (object)this.CreateXElement(parts.Skip(1), value);
        return new XElement(parts.First(), content);
    }
    

    You can then run the code like this:

    var xd = this.CreateXDocument("/Alert/Source/DetectTime", "12:03:2010 12:22:21");
    Console.WriteLine(xd.ToString());
    

    Which will produce:

    <Alert>
      <Source>
        <DetectTime>12:03:2010 12:22:21</DetectTime>
      </Source>
    </Alert>
    

    I thought I might post a variation of the CreateXElement method that should be more readable. The functionality is the same and there may even be a marginal performance improvement.

    private XElement CreateXElement(IEnumerable<string> parts, string value)
    {
        var head = parts.First();
        var tail = parts.Skip(1);
        var content = tail.Any() ?
            (object)this.CreateXElement(tail, value) :
            (object)value;
        return new XElement(head, content);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a design question and good practice question. How do you structure your
I've been thinking about this object oriented design question for a while now and
Update: Please read this question in the context of design principles, elegance, expression of
This is a somewhat bizarre question. My objectives are to understand the language design
Perhaps my question is similar in nature to this one: Do you use design
I'm struggling since a few hours with this design question. In Cocoa for example,
This is a design question. I'm trying to decide between 2 implementations. In order
This is a design question: when do I need to create/use a static method
This is a design question. If you had to create a solution with tops
This is a design question. I have data that needs to go into an

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.