my dog learned polymorphism*
The moose likes JSP and the fly likes JSTL XML TAG nesting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL XML TAG nesting" Watch "JSTL XML TAG nesting" New topic
Author

JSTL XML TAG nesting

Dilip Ganesh
Greenhorn

Joined: Sep 30, 2011
Posts: 24
Hi all,

I am parsing an xml file in jsp using JSTL xml tags.

Here the element name values are coming dynamically from other xml.

So i written the code like follows



But it is throwing the exception : <x:out tag is not terminated.

My question here is it is possible to nest a JSTL XML tags ? it is a correct way to nest the JSTL xml tags ?
Please help me.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
You can never nest a custom tag as an attribute to another custom tag.

Your expression here looks a little crazy - getting an element based on the title attribute of another element?
Maybe if you can explain what you are trying to accomplish we can suggest a better XPath. Give an example of the XML and what you are trying to get from it.
Remember that the "select" attribute of this tag is always specified as a String literal.

You might try it with two expressions:


No idea if this will work, but it might give you an idea...
Dilip Ganesh
Greenhorn

Joined: Sep 30, 2011
Posts: 24
Hi,

Thank you so much for your quick reply.



The above one will not work because select attribute doesn't accept any dynamic expression.

In my case i wants to parse the XML dynamically based on some other XML configuration. For example if i wants to parse the following XML



My configuration xml will looks follows.



So as per above configuration i need to fetch only name,id/number from person.xml. I hope its clear.Please help me. Thanks in advance.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
As you have pointed out, the xpath expressions with JSTL XML are not allowed to be dynamic.
Given that you have stated in your requirements that you want to build these dynamically based on configuration, then the JSTL XML tags are not going to be useful to you.

You can pass dynamic values to them to compare with, i.e. you could find the person with "id/number = $pageScope:idOfPersonToRetrieve"
but the actual Xpath steps must be fixed ie you can't find "person/$pageScope:RandomFieldHereBasedOnConfig".




Dilip Ganesh
Greenhorn

Joined: Sep 30, 2011
Posts: 24
Hi,

Thanks again for your reply. So in this case i am looking for some different API . If you know any API to achieve this please let me know.

Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
What is it you are trying to accomplish here?

Your problem description thus far seems to be:
- here is some random XML
- here is some XML configuration I put together that tells me how to display this sort of XML.

There is an existing technology for that - XSLT.
So I would recommend you change your custom config for an XSL template.

Whether that converts it into an XML that your page can easily display (for example name/value pairs) or produces the HTML is entirely up to your end goal.

Here is a stupid example:



Which produces:


This transforms the "random" xml into another simple xml structure.
You could then easily write a JSP page to format this structure and display name/value pairs.

The point being that you can then have
- multiple XML formats
- multiple XSL files to transform the XML into a common XML
- one JSP page to display your "common" XML structure.

I don't know if this fits your use case, and its probably over contrived, but I think applying XSL is a better solution than the custom path you seemed to be on.

 
GeeCON Prague 2014
 
subject: JSTL XML TAG nesting