Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Problem with XML syntax

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you should use "<" in place of "<" in the for loop.... "<" is the way comparison is done in XML....
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sushma Sharma
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no, actually I typed "& lt ;" (ampersand lt semicolon) without spaces, and since it is XML enabled, so it converted that into <...

 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
&lt;

Ta-dah!

(&amp;lt;)
[ July 11, 2005: Message edited by: Yuriy Zilbergleyt ]
 
Randy Gibbons
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic