File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Can I use java in XML file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Can I use java in XML file?" Watch "Can I use java in XML file?" New topic

Can I use java in XML file?

Lee Xu
Ranch Hand

Joined: Aug 24, 2001
Posts: 77
I am curious to know. Thanks
Stanley Tan
Ranch Hand

Joined: May 17, 2001
Posts: 243
What do you mean Java in XML? What would this accomplish?
Maybe you could have a Java application that writes the XML and then have another program parse it. Is that what you meant?
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
you can use Java,( using CDATA) But for what?
Since XML is more like Structured Datastorage and the realted things like XSL, Xlink are used how to interact with the XML source and display the results or do some operation. So There is no tool (as for my knowledge) to execute an XML file.
I thik you can have Javascript codes in XML and you can execute them on Clinet side by extracting them using XSL.
If you find there is any other way to use Java than the one i have mentioned, please mail me.
L Goundalkar
Sun Certified Programmer for Java 2 Platform

David O'Meara

Joined: Mar 06, 2001
Posts: 13459

appologise for my ignorance if I'm completely off track, haven't had the luxury to do as much of this as I'd like but...
Doesn't XSLT allow some java code to assist transformations, XSLT is an XML-based language therefore XML has Java support?
Actually I think I'm wrong, from
XSTL -> Java support
it doesn't necessarily follow that
XML -> Java support
Summary: I think there's this XML based thing called XSLT that has Java included in some format and this might be where Lee Xu
is coming from.

ps: thanks for the reminder once again that I need to get in and DO some of this stuff. Nag nag nag, can't a guy get any rest?
Lee Xu
Ranch Hand

Joined: Aug 24, 2001
Posts: 77
hi, All,
Thanks for your reply.
It means Java code can not appear in XML file, but can have places in XSL and CSS. Am I right?
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi David,
I still doubt if you can use Pure Java code in XSL.
Have you done it. If so then please send me the code.
I am really inetrested in this.
I think you can use Javascript but not Java.

L Goundalkar
Sun Certified Programmer for Java 2 Platform
Kevin Yip
Ranch Hand

Joined: Oct 17, 2000
Posts: 110
I doubt that the answer is no. XML is not a programming language. It's just a way to represent the hierarchy of data structure.
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
You can have inline-servlet code or jsp code inside the XSL( see Apache taglibs ) so that they get copied (as is) text to the output .html file. Checkout the taglib support in the Cocoon framework.
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
dexter ferreira

Joined: Feb 16, 2001
Posts: 7
Can you have java code in XML ? Yes you can
Can it do anything useful, being in the XML ? probably not. It will only be considered as data which the XML will store in the document.
You can use XSL and CSS to change the format of an XML document for displaying in a browser or any other application. It helps you modify/change the xml tree and add formatting and style elements to make the XML document suitable for display/inerpretation by programs/browsers.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You can use Java code inside XSL, or at least with Xalan (apache) you can without any problems (xalan extensions) you can also use Javascript, perl and python if you have IBM�s Bean Scripting Framework. What you cannot have is java(script) inside your XML to execute during transformation.
extension-element-prefixes="js metadados">
<xsl utput method="xml" indent="yes"/>
<lxslt:component prefix="metadados" elements="insert update delete">
<lxslt:script lang="javaclass" src="transform.MetadadosUpdater"/>
<xsl:if test="METADADOS/@OP='D'">
<xsl:value-of select="metadados:delete($c_id, @R_ID)"/>
I agree. Here's the link:
subject: Can I use java in XML file?
It's not a secret anymore!