Technique for creating deep elements?

R

RickH

Using the ms XMLDOM...

What techniques do you guys use to create deep elements in code for
appending to the main document as the user "adds" complex objects.

Currently I keep 3 files to do it like this:

1) The main xml file that the user is editing
2) The xsd file that validates the user-manipulated document
3) A "model" xml file that looks like the user xml file but only
contains empty element nodes or nodes with default values, and only
the bare minimum nodes needed to keep validity to the above xsd.

When the user wants to "add" a complex deep element to the main doc.
I use my model.xml file to instantiate a deep model of the complex
node they are trying to add, then I import that node into the users
document. Now the main doc contains the desired element and all it's
mandatory children.

This coding technique alleviates my code of having to actually know
what the structure is of a complex node and having to do many
appendChild commands to make it manually. IOW I basically just clone
it from the model.xml then the user fills out the values using the
existing web page code.

Are there other techniques for doing deep element creation using the
ms dom? Assuming my document has a known xsd schema, is there a
createDeepElement() or some such method? The ms DOM createElement()
method only generates a simple element, if one wants to free their
executing code from procedurally constructing complex elements, what
other techniques might be available than what I am doing?

Thanks
 
J

Joseph Kesselman

RickH said:
Using the ms XMLDOM...

I don't touch the MS code, but if they've properly implemented the DOM
APIs its behavior should be just like every other DOM. See the DOM specs
for information about what methods are available.
createDeepElement() or some such method?

No. DOM Level 3, if supported, does add some schema-directed editing --
but because schemas under-specify the real-world structure of most
documents, attempting to synthesize a tree from a schema has been found
to generally be a losing proposition. Using the schema to guide user
input generally works better, but requires a more sophisticated user
interface.
> The ms DOM createElement()

WARNING! OBSOLETE METHOD!! You should *always* be using the
namespace-aware versions these days (createElementNS() and so on).
 
R

RickH

I don't touch the MS code, but if they've properly implemented the DOM
APIs its behavior should be just like every other DOM. See the DOM specs
for information about what methods are available.


No. DOM Level 3, if supported, does add some schema-directed editing --
but because schemas under-specify the real-world structure of most
documents, attempting to synthesize a tree from a schema has been found
to generally be a losing proposition. Using the schema to guide user
input generally works better, but requires a more sophisticated user
interface.


WARNING! OBSOLETE METHOD!! You should *always* be using the
namespace-aware versions these days (createElementNS() and so on).

Thanks,

It sounds like I'm on the right track by keeping a model.xml file
(that references the same xsd) from which to derive instances of my
complex trees and business nodes. The same model.xml is also used to
intialize a new user.xml file from scratch.

I'm trying to avoid creating elements and structure programmatically
(avoiding createElement()), IOW just use the programming to fill in
the data points, with all node insertions being cloned from a valid
empty model. It's also proven to be a handy way of setting default
values for data points that the user might neglect to fill in.

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top