Re: Pollo: Editing XML files which have a DTD

Bruno Dumon <[email protected]> 13 Aug 2002 20:22:09 +0200
Newsgroups gmane.editors.pollo.devel
Message-ID <1029262929.26377.345.camel@yum>
(I've cc'ed this on the pollo mailing list, hope you don't mind, but I
thought it might be interesting for others)

On Tue, 2002-08-13 at 08:31, Scott Willy wrote:
> Bruno,
> 
> I am trying to using Pollo to edit XML files which have a DTD. I have two
> problems.
> 
> 1) Cannot open Tree View
>   When I open the attached XML file (DTD also attached), Pollo only shows
> the Text View. When try to force the Tree View by the combo box, I get an
> exception. I have the same problem if during the open I select Generic XML
> Schema or force the DTD (which from a user's view I should not have to).
> 
> 
> 
> X:\csw\java\pollo\bin>O:\devtools\java\j2sdk1.4.0\bin\java -Djava.endorsed.d
> irs=
>   ..\lib\endorsed org.outerj.pollo.Pollo
>   java.lang.ArrayIndexOutOfBoundsException
>           at
> javax.swing.text.AbstractDocument$BranchElement.getElement(AbstractDo
>   cument.java:2351)
>           at
> org.outerj.pollo.texteditor.JEditTextArea.getLineStartOffset(JEditTex
>   tArea.java:741)
>           at
> org.outerj.pollo.texteditor.CheckPanel.showParseException(CheckPanel.
>   java:52)
>           at
> org.outerj.pollo.texteditor.XmlTextEditorPanel.showParseException(Xml
>   TextEditorPanel.java:36)
>           at
> org.outerj.pollo.EditorPanelImpl$1.actionPerformed(EditorPanelImpl.ja
>   va:591)
>           at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1196)
>           at javax.swing.JComboBox.setSelectedItem(JComboBox.java:561)
>           at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:597)
>           at
> javax.swing.plaf.basic.BasicComboPopup$ListMouseHandler.mouseReleased
>   (BasicComboPopup.java:749)

If the instance document has a doctype reference, xerces will try to
load it, but can fail for various reasons (e.g. it cannot find the DTD).
I don't know of a way to tell xerces 1.4 not to load the DTD (though it
is possible with xerces 2 with a custom parser configuration).

> 2) DTD not completely honored
>   If remove the DTD reference from the XML file I can open the XML file in
> Pollo and get the Tree View.  During the open I tell Pollo to use the DTD.
> The problem I have is that the DTD specification is not completely honored.
> 
>   Pollo correctly limits the proposed child tags for any element, but does
> not restrict the number or order of the tags.
> 

yep, that's right, Pollo simply doesn't restrict those aspects. Or in
fact, it does when validating, but doesn't in the element lists. There's
an "experimental" feature though that does show the allowed content
model. It is in the menu when you choose schema -> show content model.

This feature works by actually validating the document up to the
selected element, and then asking the validator what it expects. This
means that if there are errors in the content before the selected
element, it will probably not be able to reliably detect the content
model.

So the advantage of the way it works now, is that even if the document
is full of errors, you'll still get the list of possible elements.

It's just a hard problem that AFAIK every XML editor has problems with
(well, in fact, it is not really such a problem for DTD's, but is is for
schemas, relax-ng, etc. because they don't have a one-to-one mapping
from element name to content model, since element names can be reused in
those schemas).

There are multiple ways to deal with it:
 - integrate dtd-specific functionality in pollo (i.e. not using the msv
library). Could be done, since the implementation for the schemas is
already plugable (there is a "pollo schema" and "msv schema"
implementation). The interfaces might need some refactoring and
extending though.
 - bring the afore mentioned "show content model" to a more prominent
place, i.e. make the element lists on the right switchable between this
and the current display.

If you considering doing some coding on either of these and need more
info, let me know. (I don't have a full plan ready though, and can't put
enough time in it for the moment).


>   For example the tag <test>, the DTD specifies that it can have titlex,
> purpose, testPlatform, and check as child tags. In that order. Also there
> can only be (and must be) one each of the tags titlex, purpose, and
> testPlatform and zero more or more occurrences of the check tag.
> 
>   [OT: it would be cool for Pollo to add the required child tags (and
> attributes) when adding a tag.]
> 
> Thanks for any hints (if there is some coding to do please point me in the
> right direction esp. for point 2). csw
> 
> 

--
Bruno




-------------------------------------------------------
This sf.net email is sponsored by: Dice - The leading online job board
for high-tech professionals. Search and apply for tech jobs today!
http://seeker.dice.com/seeker.epl?rel_code=31