I should mention that the problem of inserting the required elements may not be
as easy as it looks. Suppose that you have a content model like this (in BNF
notation): a|bc. Do you insert the "a" element or two elements "b" and "c"? You
have no way of knowing what the user would want.
In any case, you will probably find it interesting to look at
org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil, which is our utility for
generating an XML document based on a given Schema, and also at
SchemaType.getElementSequencer(), which creates a DFA based on the declared
content of a complex type which you can then drive using QNames. That allows
you to present the user with a list of valid elements at any given point, based
on the content already in the document.
Hope this helps,
Radu
________________________________
From: Cezar Andrei [mailto:[EMAIL PROTECTED]
Sent: Monday, November 03, 2008 10:46 AM
To: [email protected]
Subject: RE: Xml Element Insertion - Updating Dom Tree
Tim,
A good start would be the following documentation page:
http://xmlbeans.apache.org/docs/2.0.0/guide/conIntroToTheSchemaTypeSystem.html
You should check the SchemaType interface and using getContentModel()
method to check for the required particles.
Cezar
________________________________
From: Tim Dilks [mailto:[EMAIL PROTECTED]
Sent: Monday, November 03, 2008 10:08 AM
To: [email protected]
Subject: Xml Element Insertion - Updating Dom Tree
I am developing an application (a bit like XmlSpy) which allows users
to load an xml file (with an 'scomp'ed schema), and will allow insertions and
data entry.
I have a JtreeTable which I am populating using the
doc = xxxxDocument.Factory.parse(tempFile);
return (Document) doc.getDomNode();
When the user clicks on a node in the Jtree, a window is updated to
show the valid elements available for insert. I have this part all working
nicely.
The functionality I am working on implementing now is: the user clicks
an 'add' button next to a listed element, and that element should be inserted
into the tree (and of course the underlying xml). It would be good to have all
mandatory elements created for that inserted node as well.
Any high level pointers about how best to proceed here would be much
appreciated.
Thanks.