Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Technique for creating deep elements? (http://www.velocityreviews.com/forums/t479090-technique-for-creating-deep-elements.html)

RickH 03-06-2007 09:27 PM

Technique for creating deep elements?
 
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


Joseph Kesselman 03-06-2007 09:35 PM

Re: Technique for creating deep elements?
 
RickH wrote:
> 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).

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden

RickH 03-06-2007 09:48 PM

Re: Technique for creating deep elements?
 
On Mar 6, 3:35 pm, Joseph Kesselman <keshlam-nos...@comcast.net>
wrote:
> RickH wrote:
> > 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).
>
> --
> Joe Kesselman / Beware the fury of a patient man. -- John Dryden


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




All times are GMT. The time now is 08:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.