constructing xml message

Hi,

Can anyone assist on constructing an xml message.

I have an html form which has around 10 fields on submit the value is posted to a servlet which
should construct the xml message from the request parameter.

Is there any examples where I can get some info.

Thanks
Bangviz
LVL 1
bangvizAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bangvizAuthor Commented:
oops my question once again

Hi,

Case1
Can anyone assist on constructing an xml message.

I have an html form which has around 10 fields on submit the value is posted to a servlet which
should construct the xml message from the request parameter.

Is there any examples where I can get some info.

Case2
Parsing the same xml message and displaying it on the jsp


Thanks
Bangviz
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sujithkumars123Commented:
loop the request parameter names. add the name and value to the tags

StringBuffer xml = new StringBuffer();
xml.append(<params>);
Enumeration enum = req.getParameterNames();
while (enum.hasMoreElements()) {
 String name = (String)enum.nextElement();
 String value = req.getParameter(name);

 xml.append("<param>");
 xml.append("<name>");
 xml.append(name);
 xml.append("</name>");
 xml.append("<value>");
 xml.append(value);
 xml.append("</value>");
 xml.append("</param>");
}

xml.append(</params>);

This will construct your xml message for the request paramters.

Now you can write a parser for the xml file.
Display the name and value of each param.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

bangvizAuthor Commented:
BTW I have different field name,

Do i need to pass any sort of keyvalue in my html

<FORM METHOD=POST ACTION="/servlet/AddressServlet">

                  <TR>
                        <TD>Name</TD>
                        <TD>
                              <INPUT TYPE=TEXT NAME="Name" ID="name">
                        </TD>
                  </TR>
                  <TR>
                        <TD>Address</TD>
                        <TD>
                              <INPUT TYPE=TEXT NAME="Address" ID="address">
                        </TD>
                  </TR>
                  <TR>
                        <TD>City</TD>
                        <TD>
                              <INPUT TYPE=TEXT NAME="City" ID="city">
                        </TD>
                  </TR>
                  <TR>
                        <TD>State</TD>
                        <TD>
                              <INPUT TYPE=TEXT NAME="State" ID="state">
                        </TD>
                  </TR>
                  <TR>
                        <TD>email</TD>
                        <TD>
                              <INPUT TYPE=TEXT NAME="email" ID="email">
                        </TD>
                  </TR>

      <INPUT TYPE=SUBMIT NAME="submit" ID="submit" VALUE="Submit">
      <INPUT TYPE=RESET NAME="reset" ID="reset" VALUE="Reset">
      </FORM>
0
drjustinCommented:
Look at
 - xml.apache.org/xmlbeans/
 - xstream.codehaus.org/

Those are quite capable xml parsing libraries. Converting that to html should be fairly easy.
0
bangvizAuthor Commented:
I have resolved most of it..does anyone can provide a link to download SAXParser which is part of "com.ibm.xml.parsers.SAXParser"

If not how can i resolve in my code as shown below...here AddressBean is a value object with getset method...

Anticipating to hear
=========================

import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.xml.parsers.SAXParser;

import org.xml.sax.AttributeList;
import org.xml.sax.HandlerBase;
import org.xml.sax.InputSource;
import org.xml.sax.Parser;
import org.xml.sax.SAXException;

public class ResponseParser extends HandlerBase{

      private Parser parser;
       private StringBuffer sb = new StringBuffer(100);
       protected String xmlMessage;
       protected AddressBean directBean;
/**
 * ResponseParser constructor.
 */
public ResponseParser( String _xmlMessage, AddressBean _directBean ) throws SAXException, IOException {

      super();
      parser = new SAXParser();
      parser.setDocumentHandler( this );
      xmlMessage = _xmlMessage;
      directBean = _directBean;
}
public void characters(char[] buf, int offset, int len) throws org.xml.sax.SAXException {

      sb.append( buf, offset, len );
}
public void endElement(String tag) throws org.xml.sax.SAXException {
      
      String data = sb.toString().trim();

      directBean.getDataMap().put(tag,data);
      
      
}
public void parse() throws SAXException, IOException {

      ByteArrayInputStream stream = new ByteArrayInputStream( xmlMessage.getBytes() );
      InputSource input =      new InputSource( stream );
      parser.parse( input );
}
public void startElement(String tag, AttributeList attrs) throws org.xml.sax.SAXException {
      
      sb = new StringBuffer( 100 );
}
}

0
bangvizAuthor Commented:
any ideas where i can download  SAXParser which is part of "com.ibm.xml.parsers.SAXParser"

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.