Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Element ordering in DD

 
Thomas Greene
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Javaranch Mock exam

Ques
<servlet>
.........
</servlet>


<listener>
<listener-class>com.javaranch.MockListener</listener-class>
</listener>

The above entry in DD will result in what ?

Ans.

The webapp will not be loaded due to a parse exception of DD

The ordering of DD is listener then servlet

---------------------------

But i tried the following and it worked. There was no problem in loading the webapp

<servlet>
<servlet-name>A</servlet-name>
<servlet-class>com.Abc</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>A</servlet-name>
<url-pattern>/MyServlet/*</url-pattern>
</servlet-mapping>

<listener>
<listener-class>com.MyListener</listener-class>
</listener>



PLease let me know whats the correct answer. Does ordering of XML elements in DD matter ?
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it does matter. Using WebSphere, WSAD, and WebLogic I have seen such ordering errors reported by the Schema Validators. I am not sure if Tomcat is considered the model implementation of the Servlet specification.
 
P. Dunn
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe this is a straight XML/DTD question. The parser would(should)complain when loading this out of order.

The description element gave me problems. It's all over the place. The best rule I could come up with is it comes after icon, name, or id, if they exist. So for servlets and filters, it's not first. Everywhere else, it's first.

Attributes have no order in XML.

I know nothing about schemas (servlet 2.4). I don't know if they have different rules.
 
Colin Fletcher
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For 2.4 I believe the elements can be in any order. I looked in the schema definition file (xsd) and did not find a 'sequence' element.

Interesting.
-C
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic