eclipse-wildwebdeveloper / wildwebdeveloper

Simple and productive Web Development Tools in the Eclipse IDE
https://projects.eclipse.org/projects/tools.wildwebdeveloper
Eclipse Public License 2.0
186 stars 69 forks source link

XML Validation with GWT or other complex DOCTYPE - Error: Element type "ui:UiBinder" must be declared. #571

Open RobertMolenda opened 3 years ago

RobertMolenda commented 3 years ago

Validation Issues with {module}.ui.xml

Sample XML <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:gxt="urn:import:com.sencha.gxt.widget.core.client.form" xmlns:c="urn:import:com.blazent.web.client.widgets.controls" xmlns:gxtcontainer="urn:import:com.sencha.gxt.widget.core.client.container" xmlns:sl="urn:import:com.blazent.web.client.widgets.saveLoadOverlay" xmlns:form="urn:import:com.sencha.gxt.widget.core.client.form" xmlns:w="urn:import:com.blazent.web.client.widgets" xmlns:html="urn:import:com.blazent.web.client.widgets.html" xmlns:button="urn:import:com.blazent.web.client.widgets.button" xmlns:lists="urn:import:com.blazent.web.client.widgets.lists">

... page stuff here ... Error Message: Element type "ui:UiBinder" must be declared. Next Issue - Imbedded %HTMLlat1; %HTMLsymbol; %HTMLspecial; ]>
mickaelistria commented 3 years ago

Can you please try latest snapshot from https://download.eclipse.org/wildwebdeveloper/snapshots/ and report whether this works or not?

angelozerr commented 3 years ago

Element type "ui:UiBinder" must be declared.

At first I think you have this error because you declare DOCTYPE like:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui"
    xmlns:gxt="urn:import:com.sencha.gxt.widget.core.client.form"
    xmlns:c="urn:import:com.blazent.web.client.widgets.controls"
    xmlns:gxtcontainer="urn:import:com.sencha.gxt.widget.core.client.container"
    xmlns:sl="urn:import:com.blazent.web.client.widgets.saveLoadOverlay"
    xmlns:form="urn:import:com.sencha.gxt.widget.core.client.form"
    xmlns:w="urn:import:com.blazent.web.client.widgets"
    xmlns:html="urn:import:com.blazent.web.client.widgets.html"
    xmlns:button="urn:import:com.blazent.web.client.widgets.button"
    xmlns:lists="urn:import:com.blazent.web.client.widgets.lists">
  <g:HTMLPanel>
... page stuff here ...
</g:HTMLPanel>

</ui:UiBinder>

Is that?

I suggest you remove this DOCTYPE. At this step you will see no errors, no completion based on XSD. You need to write a XML catalog which defines a mapping between uri and XSD.

Create a XML file catalog gwt-catalog.xml like this :

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
    <uri
            name="urn:ui:com.google.gwt.uibinder"
            uri="http://dl.google.com/gwt/dtd/uibinder.xsd" />
    <uri
            name="urn:import:com.google.gwt.user.client.ui"
            uri="http://dl.google.com/gwt/dtd/com.google.gwt.user.client.ui.xsd" />
</catalog>

GWT Eclipse plugin does that too https://github.com/gwt-plugins/gwt-eclipse-plugin/blob/d2478f8ca89d7c388442f810cec0a44f8962aa22/plugins/com.gwtplugins.gwt.eclipse.core/plugin.xml#L946

And after that you need to register the catalog with WWD preferences:

image

Once you did that, you can open your XML and you should benefit with completion based on XSD:

image

Please note that as UiBinder is defined in http://dl.google.com/gwt/dtd/uibinder.xsd as mixed:

    <xs:element
        name="UiBinder">
        <xs:complexType
            mixed="true">

you can write any element inside it (you will not have some error).

Next Issue - Imbedded <!ENTITY records are not processed

I suggest that you create an issue for that, because by default the XML Language Server disable the load of external entities (for security reason). You can enable it with xml.validation.resolveExternalEntities like we do in vscode-xml https://github.com/redhat-developer/vscode-xml/blob/master/docs/Validation.md#resolve-external-entities but WWD doesn't provide this preference. Please create it.

RobertMolenda commented 3 years ago

Unfortunately, the problem remains.

On Tue, Nov 24, 2020 at 1:46 PM Mickael Istria notifications@github.com wrote:

Can you please try latest snapshot from https://download.eclipse.org/wildwebdeveloper/snapshots/ and report whether this works or not?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eclipse/wildwebdeveloper/issues/571#issuecomment-733224122, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4PC46JURALTR2PNPKZMK3SRQLSVANCNFSM4UBJB5PQ .

RobertMolenda commented 3 years ago

Angelo - THANK YOU - great explanation!! I hate when eclipse updates that it enables security that causes errors like this.

On Wed, Nov 25, 2020 at 3:28 AM Angelo notifications@github.com wrote:

Element type "ui:UiBinder" must be declared.

At first I think you have this error because you declare DOCTYPE like:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <ui:UiBinder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:gxt="urn:import:com.sencha.gxt.widget.core.client.form" xmlns:c="urn:import:com.blazent.web.client.widgets.controls" xmlns:gxtcontainer="urn:import:com.sencha.gxt.widget.core.client.container" xmlns:sl="urn:import:com.blazent.web.client.widgets.saveLoadOverlay" xmlns:form="urn:import:com.sencha.gxt.widget.core.client.form" xmlns:w="urn:import:com.blazent.web.client.widgets" xmlns:html="urn:import:com.blazent.web.client.widgets.html" xmlns:button="urn:import:com.blazent.web.client.widgets.button" xmlns:lists="urn:import:com.blazent.web.client.widgets.lists">

... page stuff here ... Is that? I suggest you remove this DOCTYPE. At this step you will see no errors, no completion based on XSD. You need to write a XML catalog which defines a mapping between uri and XSD. Create a XML file catalog gwt-catalog.xml like this : GWT Eclipse plugin does that too https://github.com/gwt-plugins/gwt-eclipse-plugin/blob/d2478f8ca89d7c388442f810cec0a44f8962aa22/plugins/com.gwtplugins.gwt.eclipse.core/plugin.xml#L946 And after that you need to register the catalog with WWD preferences: [image: image] Once you did that, you can open your XML and you should benefit with completion based on XSD: [image: image] Please note that as UiBinder is defined in http://dl.google.com/gwt/dtd/uibinder.xsd as mixed: you can write any element inside it (you will not have some error). Next Issue - Imbedded , or unsubscribe .
angelozerr commented 3 years ago

Unfortunately, the problem remains.

Which problems? You have again a validation problem even if you remove the DOCTYPE?

if you configure catalog, you should have completion based on XSD, no?

I hate when eclipse updates that it enables security that causes errors like this.

It's not Eclipse, it's the default behavior of the XML Language Server used https://github.com/eclipse/lemminx/

It prevent from XXE atacks, see https://www.shielder.it/blog/2019/10/dont-open-that-xml-xxe-to-rce-in-xml-plugins-for-vs-code-eclipse-theia/

The only thing that WWD must provide is the settings xml.validation.resolveExternalEntities to enable resolve external entities which can be dangerous.

mickaelistria commented 3 years ago

From Wild Web Developer, it looks like this is more a UX issue that a bug. What I think is missing:

  • Some warning in the xmlns attributes to mention that it's not resolved
  • a quick fix/code action on such warning, to "configure XML catalogs", this could use a client-side command which the IDEs can decide to interpret at they want (eg showing the preference page for Eclipse IDE).

@angelozerr do you want me to open tickets to lemminx about that, or are those stories already covered is some way Wild Web Developer fails at leveraging?

For this example, I'd suggest @RobertMolenda you use actual XSD path (eg http://dl.google.com/gwt/dtd/uibinder.xsd ) in the xmlns elements instead of the "to be resolved" urn: ones.

angelozerr commented 3 years ago

Some warning in the xmlns attributes to mention that it's not resolved

XML errors are reported by Xerces, and in this case, Xerces consider that it's a XML valid, because you can use namespace without XSD association. I think it's possible to support this warning, but I'm not sure it's an easy task.

When XML is not bound to a XSD, DTD grammar, you can see an information on the root element. The last release of LemMinx provides several code actions to generate XSD / DTD and associate it:

image

a quick fix/code action on such warning, to "configure XML catalogs", this could use a client-side command which the IDEs can decide to interpret at they want (eg showing the preference page for Eclipse IDE).

I think it's a new CodeAction that we should implement like we did to generate XSD, DTD. An idea is to generate the XML catalog and if LSP client have the capability,it can register the catalog on settings client side. We did this kind of feature when XML catalog path is wrong.

For this example, I'd suggest @RobertMolenda you use actual XSD path (eg http://dl.google.com/gwt/dtd/uibinder.xsd ) in the xmlns elements instead of the "to be resolved" urn: ones.

Why, XML catalogs is working for that, no? I'm not sure that @RobertMolenda want to modify the gwt xml which uses namespaces.

mickaelistria commented 3 years ago

What's to be done on LSP4E on that matter? It seems like everything is in place to make it work.

angelozerr commented 3 years ago

What's to be done on LSP4E on that matter? It seems like everything is in place to make it work.

For which feature?

To fix this issue WWD should provide the settings xml.validation.resolveExternalEntities to enable resolve external entities which can be dangerous. IMHO I think WWD should expose as UI preferences all LemMinx settings (enable codelens, format settings, etc) and settings which give the same behaviour than WTP editor (see https://github.com/eclipse/wildwebdeveloper/issues/557).