You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Hellmann Peter (ext)" <Pe...@mch.siemens.de> on 2002/11/06 18:14:58 UTC

right-sequencing of child tags in dom

hi all,

please allow me one question. because no validation occurs while adding
nodes to a dom tree (no dynamic validation) i can add some child nodes to my
dom tree in the wrong sequence (DTD says <tag1> must come before <tag2> but
i can add nodes in an arbitrary order). Because when serializing, no
validation is done, my unmarshalled output contains the tags in the wrong
sequence. now my question is if there is any function that does
right-sequencing child nodes according to the settings in the DTD prior to
serialization?

thanx 4 any hints

kind regards
Peter Hellmann

Siemens Aktiengesellschaft
Information and Communication Networks
Voice & Data Recording
ICN WN CS VDR RD
Hofmannstraße 51              +49 89 722 49347
office 1746.441               +49 89 722 22985
D-81379 München               peter.hellmann@mch.siemens.de
<ma...@mch.siemens.de> 
GERMANY


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: right-sequencing of child tags in dom

Posted by Joseph Kesselman <ke...@us.ibm.com>.
... My apologies; I think I misread the question.

If by "right sequence" you mean "to conform with a specific DTD or schema" 
-- there's no standard API yet that will help you with this. The DOM 
Working Group is still interested in addressing this, but they changed 
their approach a while back and I'm not sure what state that effort's 
currently in. Xerces has some custom APIs which allow accessing the 
schema, but I haven't used them enough to advise you on whether they'd 
give you all the information you need.

I agree with the point that automatically reordering would risk breaking 
the user's intent. It's probably better to generate a validly-structured 
tree in the first place, under the guidance of information retrieved from 
the schema, and to provide tools to check validity.

Sometimes the simplest answer is to hard-code knowledge of the specific 
document's structure into your application, so the children *have* to be 
generated in the right order.

______________________________________
Joe Kesselman  / IBM Research

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: right-sequencing of child tags in dom

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
With the tools I've used, the best you can do is to try to validate your
DOM, and fix it up yourself if validation fails.  Validating the DOM can
either be done using the Xerces 2 DOM Level 3 Validation stuff, or by
serializing the DOM and reparsing.  If you use the DOM Level 3 validation
interfaces, you can validate on each edit of the DOM, thus avoiding the
ordering problem.

While it is true that for any valid instance of any valid DTD content model,
there is an unambiguous assignment of elements of the instance to items in
the content model, ambiguity appears if you allow rearrangements of the
order of children.  If at each node in the DOM you allow arbitrary
reorderings of the children in order to match the content model, there will
be cases where more than one correct solution is possible (perhaps a huge
number).  You would either have to have the algorithm choose the first one
that worked, or present you with all of them to pick from.

Jeff
----- Original Message -----
From: "Hellmann Peter (ext)" <Pe...@mch.siemens.de>
To: "Xerces (E-Mail)" <xe...@xml.apache.org>
Sent: Wednesday, November 06, 2002 9:14 AM
Subject: right-sequencing of child tags in dom


hi all,

please allow me one question. because no validation occurs while adding
nodes to a dom tree (no dynamic validation) i can add some child nodes to my
dom tree in the wrong sequence (DTD says <tag1> must come before <tag2> but
i can add nodes in an arbitrary order). Because when serializing, no
validation is done, my unmarshalled output contains the tags in the wrong
sequence. now my question is if there is any function that does
right-sequencing child nodes according to the settings in the DTD prior to
serialization?


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org