| Author |
Problem with XML syntax
|
Randy Gibbons
Greenhorn
Joined: Feb 06, 2005
Posts: 14
|
|
I am experimenting with the XML syntax alternative in JSPs. in the fragment below, the compiler is tripping up on the "<" in the for loop and concluding that my <jsp:scriplet> element doesn't have a valid end tag. I tried replacing "<" with "<" and my intuition was right that that simply replaces a parsing error with a syntax error. How do I escape the "<" or otherwise do something to eliminate this problem? (I prefer a solution that doesn't involve using the Expression Language.) <CODE> ... <TABLE BORDER=1> <jsp:scriptlet> Iterator entries = request.getParameterMap().entrySet().iterator(); while(entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); String key = (String) entry.getKey(); String[] values = (String[]) entry.getValue(); for(int i = 0; i < values.length; i++) { </jsp:scriptlet> <TR><TD><jsp:expression> key </jsp:expression> <TD><jsp:expression> values[i] </jsp:expression> <jsp:scriptlet> } } </jsp:scriptlet> </TABLE> ... </CODE>
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
I am experimenting with the XML syntax alternative in JSPs.
Why? Are you auto-generating this code? The XML syntax is intended as an intermediate format for JSP containers to use internally, and for JSPs that are auto-generated by code that wish to create an in-memory DOM of the page and then serialize it. Hand-coding the XML syntax is not really an intended usage.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Sushma Sharma
Ranch Hand
Joined: Jun 02, 2005
Posts: 139
|
|
|
I think you should use "<" in place of "<" in the for loop.... "<" is the way comparison is done in XML....
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Originally posted by Sushma Sharma: I think you should use "<" in place of "<" in the for loop.... "<" is the way comparison is done in XML....
I'm assuming there is a typo in that statement somewhere
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Sushma Sharma
Ranch Hand
Joined: Jun 02, 2005
Posts: 139
|
|
no, actually I typed "& lt ;" (ampersand lt semicolon) without spaces, and since it is XML enabled, so it converted that into <...
|
 |
Yuriy Zilbergleyt
Ranch Hand
Joined: Dec 13, 2004
Posts: 429
|
|
< Ta-dah! (&lt;) [ July 11, 2005: Message edited by: Yuriy Zilbergleyt ]
|
 |
Randy Gibbons
Greenhorn
Joined: Feb 06, 2005
Posts: 14
|
|
Bear B. asks why I am trying to do this. Answer: Just as part of teaching myself Servlets & JSPs. I understand your point and might never use the XML syntax in practice, though the two books I am using -- Marty Hall and Larry Brown's Core Servlets and JavaServer Pages, Second Edition (see chapter 11 on XML syntax) and The J2EE Tutorial, Second Edition (see chapter 13 on JavaServer Pages Documents) -- don't seem to find anything wrong with using it even in a non-auto-generated development environment. The Tutorial even suggests some advantages. Sushma: In my original post I attempted to say that I had already tried the character entity 'ambersand lt ;' (which, as in your original reply, got translated into '<'!). The point was that when I do that, I get a syntax error (i.e., the XML parser now recognizes the validity of my <jsp:scriptlet>...</jsp:scriptlet> start and end tags, but the compiler compiling the Java code between these tags chokes on the character entity, which of course is not valid Java syntax. So my problem remains unsolved. (Going back to Bear's point, I wonder what an auto-generator would do?)
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
I wonder what an auto-generator would do?
It would create full-compliant XML. That means using CDATA sequences and entities where appropriate. Which is why I see no advantage to the XML syntax for hand-coded pages. Once you've added all the necessary markup to keep the page legal, it's an unreadable (at least by humans) mass of markup goo that obfuscates the actual content of the page. YMMV.
|
 |
Randy Gibbons
Greenhorn
Joined: Feb 06, 2005
Posts: 14
|
|
Originally posted by Bear Bibeault: It would create full-compliant XML. That means using CDATA sequences and entities where appropriate. Which is why I see no advantage to the XML syntax for hand-coded pages. Once you've added all the necessary markup to keep the page legal, it's an unreadable (at least by humans) mass of markup goo that obfuscates the actual content of the page. YMMV.
Point taken! Even my simple page is indeed an unreadable mass of markup goo. But I can still be curious ...
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
But I can still be curious
Curious is good! I guess I just feel that there are more important (and practical) concepts that you could be curious about!
|
 |
 |
|
|
subject: Problem with XML syntax
|
|
|