views:

216

answers:

5

I'm writing a document-based client application and I need a DOM or WPF-like, but non-visual model that:

  • Is a tree composed of elements
  • Can accept an unlimited number of custom properties that
    • get/set any CLR type, including collections.
    • Can inherit their values from their parent
    • Can inherit their default values from an ancestor
    • Can be derived/calculated from other properties, ancestors, or descendants
    • Support event bubbling / tunneling
    • There will be a core set of properties but other plugins may add their own or even create custom documents
  • Supports full inspection by the owning document in order to persist the tree and attributes in an XML format.

I realize that's a tall order but I was really hoping there would be something out there to help me get started. Unfortunately WPF DependencyObjects are too closed, proprietary, and coupled to WPF to be of any use as a document model. My needs also have a strong resemblance to the HTML DOM but I haven't been able to find any clean DOM implementations that could be decoupled from HTML or ported to .NET.

My current platform is .NET/C# but if anyone knows of anything that might be useful for inspiration or embedding, regardless of the platform, I'd love to know.

+1  A: 

I don't think that it meets all of the requirements you specified, but have you considered working with an XML DOM (as opposed to an HTML DOM)? You can create an XML document programmatically in .NET and manipulate it using DOM methods and properties, and also do things like XPath queries. Check out .NET's XmlDocument object. This might be a reasonable starting point.

RMorrisey
A: 

Maybe XMLBeans could help.

kiwicptn
A: 

Eclipse EMF might help, but it might also be overkill for you. IMHO good designed language should make such a task extremely easy...

Gabriel Ščerbák
A: 

Netbeans platform pretty much does exactly what you want.

Mike
A: 

Are you looking for advice for an object model? How about:

// C#-ish code that probably doesn't compile
class Element {
    public object GetAttribute(string attribute) {
        if (this.Attributes.HasKey(attribute))
            return this.Attributes[attribute];
        else
            return this.Parent.GetAttribute(attribute);
    }

    private IDictionary<string,object> Attributes;

    private Element Parent;
    private IList<Element> Children;    // maybe not needed

    // etc.
}

and go from there?

apollodude217