• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting a value in an XML

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a small XML file. The structure of the file is like this :
<ADDRESS>
<tag id="company" value="300 N Washington Avenue" />
</ADDRESS>
Now here the "value" attribute is given a static value.
I want to give it The value which is coming from a JSP page, when I submit the page.
ie, if I have String x = request.getParameter("address");
I want to make this String x as the attribute value.
How will I do this ?
My env is
Apache Web Server 1.1.13
Apache JServ1.1
Windows 2000
jdk 1.3.1
I still have to figure out a parser that can be used for my purposes.
Any suiggestions.. Please
Thanks,
Maya

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure how far my solution is going to solve u r problem. Just give a thought to my solution and let me know if it helps you.
since you want to pass an attribute value into your xml file, I suggest you to create your xml file in Jsp file.
For exmample,
String x = request.getParameter("address");
try{
FileOutputStream fout = new FileOutputStream(new File("address.xml"));
String xml = " <ADDRESS> " +
" <tag id=\"company\" value=\"" + x + "\" />" +
"</ADDRESS>" ;
bytes b[] = xml.getBytes();
fout.write(b);
}
catch(Exception e) {
System.out.println(e);
}

The first statement in try block will create address.xml file into which you can pass the value of 'x' as an attribute value of the node tag.
I feel it would be better approach if the size of xml is considerably small. If it is an external file, you may have to parse the file using either SAX or DOM parser, catch the attribute of the node tag and replace the value of the desired attribute.
waiting to hear from you, if you feel it a valid suggestion. My email is pvvnath@yahoo.com
 
reply
    Bookmark Topic Watch Topic
  • New Topic