0

Hey i have a situation in which i need to pass some variable value in jsp to xml file.

for example if i have int a = 10;

and i want to pass value of "a" to xml file which is something like:-

<graph caption='Estimated Renewal Cost' xAxisName='Year' yAxisName='Units (US Dollars)' showNames='1' decimalPrecision='0' formatNumberScale='0'>
    <set name='Backlog' value='19273773' color='AFD8F8' />

</graph>

so in i want the value of "a" to be brought at value attribute of set tag in xml.

Actually i'm using fusion charts to generate graph and want to have dynamic graph which may change according to my jsp page. And as far as i know fusion charts only accept data in xml format.

I have no experience with xml.

1
  • What exactly is your problem? Do you want to generate an XML file and pass it to fusion? Commented Aug 12, 2011 at 16:15

1 Answer 1

1

Your question doesn't make much sense. An XML file is just that: a file. It doesn't contain any executable or interpreted statement.

You probably want to dynamically generate an XML file (or stream), but unless the output generated by the JSP is this XML file (after all, JSPs typically generate (X)HTML, and can be used to generate other kinds of XML documents), it's not really a task that a JSP should do. A servlet is the place where such a task should be done.

If you want to generate an XML document, you have many choices: DOM, JDOM, dom4j, JAXB, or even plain string concatenation (although I would not recommend it, except if all you need to do is generating such a small document with only one dynamic attribute).

Sign up to request clarification or add additional context in comments.

2 Comments

Hey thanks, actually i need to generate xml dynamically, and the example which mentioned was just to provide explanation of what i exactly want to do. I want to directly generate over jsp because a graph usually comprises of at max 5 values, so i think its okay. But the point is how?
As I said, you have many many choices. Google for "generate XML in Java", and for the keywords I gave you to find tutorials. I personally like JAXB, but YMMV.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.