You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jerry Malcolm <2n...@gmail.com> on 2013/04/20 20:14:21 UTC

JSTL XML Basic Question

I have been searching for several hours for a basic JSTL answer with no
luck.  From what I can tell, JSTL is under the umbrella of Tomcat.
Hopefully someone can help me out.

I simply want to use an existing already-parsed DOM (org.w3c.dom.Document
variable) with JSTL XML tags.  In other words, I want to skip the x:parse
step and just tell x:out and all of the other x tags to pull data from my
pre-existing pre-parsed DOM:

       Document myDOM;  // already built by another part of the code

I understand basic xpath stuff.  But I'm not sure how to tell it to use a
standard local java variable for the DOM.

I've tried   <x:out select="$myDOM/aaaaa/bbbbb"/>  and <x:out
select="${myDOM}/aaaaa/bbbbb"/>

Both give me errors that seem to say it doesn't find a DOM.

Every example I can find always assumes I want to start with a true
non-parsed XML document.

I'm sure I'm missing something obvious.  But can someone please help me out
with the correct syntax?

Thanks.

Jerry

Re: JSTL XML Basic Question

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/4/20 Jerry Malcolm <2n...@gmail.com>:
> I have been searching for several hours for a basic JSTL answer with no
> luck.  From what I can tell, JSTL is under the umbrella of Tomcat.
> Hopefully someone can help me out.
>

You are welcome.

> I simply want to use an existing already-parsed DOM (org.w3c.dom.Document
> variable) with JSTL XML tags.  In other words, I want to skip the x:parse
> step and just tell x:out and all of the other x tags to pull data from my
> pre-existing pre-parsed DOM:
>
>        Document myDOM;  // already built by another part of the code
>

1. Have you exposed your Java variable as JspContext attribute?

I mean,  pageContext.setAttribute("myDOM", myDOM)?

> I understand basic xpath stuff.  But I'm not sure how to tell it to use a
> standard local java variable for the DOM.
>
> I've tried   <x:out select="$myDOM/aaaaa/bbbbb"/>  and <x:out
> select="${myDOM}/aaaaa/bbbbb"/>
>

2. The first should work.
The second in not valid, neither by JSTL spec, nor by XPath spec.

The latter says,
[36]   VariableReference   ::=   '$' QName

I have not actually tried it, though.

JSTL spec says:

[quote]
An XPath expression must also treat variables that resolve to implementations of
standard DOM interfaces as representing nodes of the type bound to
that interface
by the DOM specification.
[/quote]

1) What is the structure of your document

2) Maybe:  try to select a specific XML element and put it into
JspContext's attribute. Then try to output it via <x:out
select="$elem"/>.

> Both give me errors that seem to say it doesn't find a DOM.
>

How this error looks like, exactly, with a stacktrace?

> Every example I can find always assumes I want to start with a true
> non-parsed XML document.
>
> I'm sure I'm missing something obvious.  But can someone please help me out
> with the correct syntax?
>

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: JSTL XML Basic Question

Posted by Martin Gainty <mg...@hotmail.com>.
Jerry

You'll need core taglib and xml taglib e.g. http://www.tutorialspoint.com/jsp/jstl_xml_out_tag.htm
declaration:<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
 use core taglib to set var:<c:set var="xmltext">
  <books>
    <book>
      <name>Padam History</name>
      <author>ZARA</author>
      <price>100</price>
    </book>
    <book>
      <name>Great Mistry</name>
      <author>NUHA</author>
      <price>2000</price>
    </book>
  </books>
</c:set>
 use xml taglib to set parse var:
<x:parse xml="${xmltext}" var="output"/>
 use xml taglib to set output the parsed text<x:out select="$output/books/book[1]/name" />
 http://www.tutorialspoint.com/jsp/jstl_xml_out_tag.htm
Martin______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.

 > Date: Sat, 20 Apr 2013 13:14:21 -0500
> Subject: JSTL XML Basic Question
> From: 2ndgenfilms@gmail.com
> To: users@tomcat.apache.org
> 
> I have been searching for several hours for a basic JSTL answer with no
> luck.  From what I can tell, JSTL is under the umbrella of Tomcat.
> Hopefully someone can help me out.
> 
> I simply want to use an existing already-parsed DOM (org.w3c.dom.Document
> variable) with JSTL XML tags.  In other words, I want to skip the x:parse
> step and just tell x:out and all of the other x tags to pull data from my
> pre-existing pre-parsed DOM:
> 
>        Document myDOM;  // already built by another part of the code
> 
> I understand basic xpath stuff.  But I'm not sure how to tell it to use a
> standard local java variable for the DOM.
> 
> I've tried   <x:out select="$myDOM/aaaaa/bbbbb"/>  and <x:out
> select="${myDOM}/aaaaa/bbbbb"/>
> 
> Both give me errors that seem to say it doesn't find a DOM.
> 
> Every example I can find always assumes I want to start with a true
> non-parsed XML document.
> 
> I'm sure I'm missing something obvious.  But can someone please help me out
> with the correct syntax?
> 
> Thanks.
> 
> Jerry
 		 	   		  

Re: JSTL XML Basic Question

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Jerry,

On 4/20/13 2:14 PM, Jerry Malcolm wrote:
> I have been searching for several hours for a basic JSTL answer
> with no luck.  From what I can tell, JSTL is under the umbrella of
> Tomcat.

Nope, but I can understand the confusion.

JSTL is a standard that describes a set of JSP tags. "Jakarta Taglibs"
aka "Apache Taglibs" (found under the Tomcat umbrella) is one
implementation of the JSTL specification. At this point, it's
basically a dead project because apparently nobody cares about it anymore.

I think just about everyone uses Glassfish's implementation:
https://jstl.java.net/

> I simply want to use an existing already-parsed DOM
> (org.w3c.dom.Document variable) with JSTL XML tags.  In other
> words, I want to skip the x:parse step and just tell x:out and all
> of the other x tags to pull data from my pre-existing pre-parsed
> DOM:
> 
> Document myDOM;  // already built by another part of the code
> 
> I understand basic xpath stuff.  But I'm not sure how to tell it to
> use a standard local java variable for the DOM.
> 
> I've tried   <x:out select="$myDOM/aaaaa/bbbbb"/>  and <x:out 
> select="${myDOM}/aaaaa/bbbbb"/>
> 
> Both give me errors that seem to say it doesn't find a DOM.
> 
> Every example I can find always assumes I want to start with a
> true non-parsed XML document.
> 
> I'm sure I'm missing something obvious.  But can someone please
> help me out with the correct syntax?

Try using <x:parse> and then dumping-out the (Java) type of the
resulting object. Perhaps JSTL uses something other than a "Document"
object (or maybe you are not naming your reference correctly).

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJRda5yAAoJEBzwKT+lPKRYs1MP/R2rCgZd+a93YeXH1ATn6gES
WQZpuMBaBsecTqehepMAG8iRPfFrbu+d6tk2vredHui3bi+yXZRW69nGEtNSt7kJ
sRTF3mZ3/sg+MpoMXg5Lo9iG5PxCdZIcHVWrbfTjA43nZ+84XYBLONkZnrut7qKp
BmbyvKy+uwLJ8T5xLUcfhE7Qwzv/66qCARuAcKdQSqm8Yj77SYtnr/K+DvAC9Cca
7A5c9oin3n4cs5kHOcJg10Sd3MOT+0R9PzLX1+0xBBufiDB5AWywDMYk8g7zvXiK
qHn84f+p7eBU7P+z73FhervmPrHv7DQDn57uIxQkzxuS7sX5McPsS+fOeJpnUZRw
o9vt2E2/4v8sX/OrJnmcgKX7seRjswIKQMBeHJ9/DqAa0drrPjbK9bgpxUd4VkAj
X8QRl8Mp61Jv3yTShzETJyID28rhUHRjJPgS0NNI4NwgMwFfTSAMp6Ja42YZl0rT
rVDZXtKJ6d1W7Dc0MGRxPJ+CgK91OqHUDf/OpNHe9J6ySt+nyBd3sYFmGaUp0evp
kJzg4I8w8X2tbZfAo3fLLEuFopPoDN21Tu0W73G/uKzU+6hQzi2VkPIz+x8vcn5H
JsSxT2ufxitXC++RDxFCEKle9EPY7UyptxTV2u0FIYEmKgp48lN3igXEGBIMuNH1
69I9IgFQLLvoyOuTc1jd
=z7k1
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org