The content of element type “struts-config” must match “(datasource?,form-beans?

priya picture priya · Mar 2, 2011 · Viewed 8.1k times · Source

I wrote a small struts application with a login page and registration page. If I login I get a success page. If i register, i will check the password and confirm password fileds if they match i get a success page else failure page.

I did not use any database. I wrote the required Form Beans, Action Classes of those.

In struts-config.xml it is showing an error at the <struts-config> tag:

"The content of element type “struts-config” must match “(datasource?,form-beans?,global-forwards?,action-mapping?)"

How to resolve this problem? I am using Eclipse as my IDE.

Answer

zb226 picture zb226 · Jul 29, 2015

Yes, the struts-config.xml is invalid according to the schema, but as the app is working, it's only a validation issue. To expand on why it is invalid in the context of the order of the child elements - If the validator is telling you that...

The content of element type “struts-config” must match “(datasource?,form-beans?,global-forwards?,action-mapping?")

...then that means that e.g. (reduced examples for brevity):

<struts-config>
  <datasource>...</datasource>
  <form-beans>...</form-beans>
  <global-forwards>...</global-forwards>
  <action-mapping>...</action-mapping>
</struts-config>

...is a valid implementation of the schema, while e.g. ...

<struts-config>
  <datasource>...</datasource>
  <global-forwards>...</global-forwards>
  <form-beans>...</form-beans>
  <action-mapping>...</action-mapping>
</struts-config>

...is not. This, by the way, is due to the fact that the Struts 1.0 DTD in question says...

<!ELEMENT struts-config (data-sources?,form-beans?,global-forwards?,action-mappings?)>

...and by that demands a certain order of child elements. This is not something that the DTD authors do inadvertently, but due to fact that:

Declaring unordered lists with occurrence constraints in DTD will often result in long or complicated looking declarations. 1