tags:

views:

75

answers:

6

Hi

i am new for XML.i have a function that takes four input.on the basis of these four parameter create an XML using Java.for example:

<?xml version="1.0" encoding="UTF-8">
<validateemail>
<emailid>[email protected]</emailid>
<address>abc,street</address>
</validateemail>

After that formed XML is return as String.please guide me.

Thanks

+1  A: 

Perhaps you should go through some tutorial related to this. This is the first one that I found in google search.

Raghuram
+1  A: 

There are different ways of generating XML: DOM, SAX, JAXP. I prefer DOM over e'thing because of its' simplicity. You can try this link: http://genedavis.com/library/xml/java_dom_xml_creation.jsp

tanjir
+1  A: 

The built-in XML APIs in Java can be a bit of a pain. You may want to use something like JDOM instead (or any of the many other APIs available). There are various tutorials available, including this one which covers quite a bit of the API simply.

Jon Skeet
A: 

I'm supposing the final xml to look like this:

<?xml version="1.0" encoding="UTF-8"> 
<validateemail> 
 <emailid>[email protected]</emailid> 
 <address>abc,street</address> 
 </validateemail>

instead of directing you towards the APIs, here is something to just get you started: you would have to use StringBuilder object.

StringBuilder sb = new StringBuilder();
 sb.AppendLine("<?xml version="1.0" encoding="UTF-8">");

then add the parameters accordingly,

sb.AppendLine("<validateemail>");
sb.AppendLine("<emailid>"+emailidvalue+"</emailid>");

The same can be done for other parameters as well. This is only a rough idea for the problem. how you implement it is strictly upto you.

Anurag
make sure you escape the " characters
Anurag
A: 

You can also check a previous question:Reading xml as string in java

Nervo Verdezoto
I posted there how to get data from a XML file!!
Nervo Verdezoto
A: 

You can use Java DOM API, it's the easiest way. "Link"

Dorr