How get xml-data at servlet by http and parse it?

hello! please help me who can, i have very urgent task but not much skilful to deal with work in web. is anywhere source code or similar example of task to get xml-data at servlet by http and parse it . thank you in advance

here a basic code that reads and parses an remote xml file:
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class SAXParserExample extends DefaultHandler {
     StringBuffer buffer;
     String urlString = "http://nds.nokia.com/uaprof/NN95_8GB-1r100.xml";
     public SAXParserExample() {
     public void runExample() {
          parseDocument();
     private void parseDocument() {
          // get a factory
          SAXParserFactory spf = SAXParserFactory.newInstance();
          try {
               // get a new instance of parser
               SAXParser sp = spf.newSAXParser();
               URL url = new URL(urlString);
               HttpURLConnection httpSource = (HttpURLConnection) url.openConnection();
               // parse the file and also register this class for call backs
               sp.parse(httpSource.getInputStream(), this);
          } catch (SAXException se) {
               se.printStackTrace();
          } catch (ParserConfigurationException pce) {
               pce.printStackTrace();
          } catch (IOException ie) {
               ie.printStackTrace();
     // Event Handlers
     public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
          System.out.println("+++ start of element: " + qName);
          buffer = new StringBuffer();
     public void characters(char[] ch, int start, int length) throws SAXException {
          buffer.append(ch, start, length);
     public void endElement(String uri, String localName, String qName) throws SAXException {
          System.out.println(buffer.toString());
          System.out.println("+++ end of element " + qName);
     public static void main(String[] args) {
          SAXParserExample spe = new SAXParserExample();
          spe.runExample();
}you have only to change the urlString and adapt to your needs.
hope it helps

Similar Messages

  • How to get javabean data in Servlets.( JavaBean -- Servlet(Controller)

    how to get javabean data in Servlets.
    1) I am using name ,password in Jsp(View )
    2) when I submit this Bean will be called and Setter methods will be called .
    3) In ServletController (controller) I want to get data of javabean.
    In this I have to do validation of user.
    I want to pass the javabean obj as like -->
    request.getAttribute("beanObj");
    My intention is to get all the poperties in javabean by passing bean id
    or beanobj ,
    Is there any way to get all the data using bean id or beanObj.
    Plz Reply,

    Now in the Servlet we can get the same bean by this code:
    PageContext pageContext = JspFactoryImpl.getDefaultFactory().getPageContext(this, request, response, null, true, 8192, true);
    UserBean userbean = (UserBean)pageContext.getAttribute("userbean", PageContext.SESSION_SCOPE);
    String userid = userbean.getUsername();
    For this code to work it is needed to import 2 files:
    import org.apache.jasper.runtime.JspFactoryImpl;
    import javax.servlet.jsp.PageContext;
    The JspFactoryImpl is in jasper-runtime.jar file provided in tomcat dir.It seems to me that you are exactly knowing what you are doing :-(
    You can get a Bean stored in a Session by
    request.getSession().getAttribute("userbean");
    In the login.jsp page for example we have the code
    <jsp:useBean id="userbean" scope="session"class="com.newproj.UserBean" />
    <jsp:setProperty name="userbean" property="*" />the jsp:setProperty is not called when you click on the submit button
    if fills the bean with the request values from the previous request.
    andi

  • How to get the data in servlet if the request encryption type is multipart/

    I am uploading files to the server.
    at that time,before upload ,I need to validate the upload file names.
    so,i am trying to get the value of those files names using
    request.getParameter("jobsheet"); in servlet.
    its giving null insted of file path.
    how to retrieve the the values of parameters if the request is multipart/form-data.
    any help please...

    I think that package works in struts framework right?
    If wrong ,correct me.
    actually I am following MVC pattern.not using struts.
    If this works even in normal web application also.then ok.
    But,Just I am looking how to get the values of jsp parameters
    I have 5 elements in jsp .
    below code:
    <form name="FileUpload" action="./UploadServlet" method="post" enctype="multipart/form-data">
    country <input type="text" name="country" value="">
    year <input type="text" name="year" value="">
    month <input type="text" name="month" value="">
    File<input type="file" name="file1" value="">
    <input type="submit">
    </form>
    I am trying to get the data in servlet like
    String country=req.getParameter("country");
    its getting null.
    I don't know how to get the values if the enctype is "enctype="multipart/form-data"
    If any one knows ,Please suggest me.

  • Read/get xml data (string)

    Hi
    I have a XML string that I get from a TCP transfer, I have attached a received string.
    I have no experience in reading XML data, I have tried looking in the forums and some of the examples in LV, but I cannot get it to work, so I hope that someone could help me out. All I need to get from the XML data are the names e.g. Station1 and Station2 perhaps putted into a string array. If so it wouldn't hurt to get all the rest parameters and attributes as well. I thought about doing some string searches to get what I need, but thought again that it might be easier/better in some way to take advantage of the data being arranged as XML.
    Hope that someone can help.
    Thanks in advance
    Best regards
    Simon
    LabVIEW 8.6 / 2009 / 2010
    Vision Development Module 8.6 / 2009 / 2010
    VBAI 3.6 / 2010
    Attachments:
    testmap.txt ‏1 KB

    Hi all
    falkpl wrote:
    The easy way is if you know that this string is not changing much you treat it as a formated string and parse it using simple string functuions
    ie first parse %s and %s The two slashes will cancle the escape clause of the string parser.  Repete this process to get each station and attributes.
    The harder way is to use an activeX or .net XML parser.
    Paul
    I am not sure what you mean about the parser, well I get the concept, but is there a specific string function that can do that for me?
    I got something working with the Match Pattern vi, please the attached. This actually works for my current needs, but I still would be able to get data from more complex XML data.
    Hi A.K. and J.K.
    Thank you for the link.
    EasyXML looks like a nice and handy tool for handling XML data. I ran in too some problems though when running the VI Package Manger. When I check the network for new packages it says that there was an error, please check the network connection or settings. I have internet connection (I am writing this post ) and I am not using a proxy server. What could be wrong and how do I install EasyXML then, is there another way?
    Best regards
    Simon
    LabVIEW 8.6 / 2009 / 2010
    Vision Development Module 8.6 / 2009 / 2010
    VBAI 3.6 / 2010
    Attachments:
    my_get_xml_data.vi ‏15 KB

  • Get XML data into SAP

    Hi ,
    Is there any function module to get XML data into SAP?
    If function module doesnt exist, suggest alternative to do it.
    Thanks,
    Shivaa...

    Hi Shiva ,
    there is lot of stuff regarding ur query in SDN....
    anyways check this link...
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/upload%252bxml%252bfile%252bto%252binternal%252btable
    hope this solves ur problem.
    Regards,
    Anuj

  • How to upload data from excel to SAP and options to be used

    How to upload data from excel to SAP and options to be used
    thank you,
    Regards,
    Jagrut Bharatkumar shukla

    Hi Jagrut,
        You can use gui_upload.
    chk the sample program mentioned below.
    REPORT ZFTP .
    DATA: BEGIN OF I_FILE OCCURS 0,
    DATA(2000) TYPE C,
    END OF I_FILE.
    DATA: BEGIN OF I_FILE2 OCCURS 0,
    DATA(2000) TYPE C,
    END OF I_FILE2.
    DATA: W_COUNT TYPE I.
    PARAMETERS: P_FILEN TYPE STRING,
    P_FILE2 TYPE STRING,
    P_NUM(4) TYPE N..
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILEN.
    PERFORM F_FILE_GET USING P_FILEN TEXT-G01.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE2.
    PERFORM F_FILE_GET USING P_FILE2 TEXT-G01.
    START-OF-SELECTION.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = P_FILEN
    FILETYPE = 'ASC'
    HAS_FIELD_SEPARATOR = 'X'
    HEADER_LENGTH = 0
    READ_BY_LINE = 'X'
    DAT_MODE = ' '
    CODEPAGE = ' '
    IGNORE_CERR = ABAP_TRUE
    REPLACEMENT = '#'
    CHECK_BOM = ' '
    VIRUS_SCAN_PROFILE =
    NO_AUTH_CHECK = ' '
    IMPORTING
    FILELENGTH =
    HEADER =
    tables
    data_tab = I_FILE
    IF SY-SUBRC <> 0.
    MESSAGE E024(Z1).
    ENDIF.
    LOOP AT I_FILE.
    W_COUNT = W_COUNT + 1.
    IF NOT W_COUNT > P_NUM.
    MOVE I_FILE TO I_FILE2.
    APPEND I_FILE2.
    ENDIF.
    ENDLOOP.
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    BIN_FILESIZE =
    filename = P_FILE2
    FILETYPE = 'ASC'
    APPEND = ' '
    WRITE_FIELD_SEPARATOR = 'X'
    HEADER = '00'
    TRUNC_TRAILING_BLANKS = ' '
    WRITE_LF = 'X'
    COL_SELECT = ' '
    COL_SELECT_MASK = ' '
    DAT_MODE = ' '
    CONFIRM_OVERWRITE = ' '
    NO_AUTH_CHECK = ' '
    CODEPAGE = ' '
    IGNORE_CERR = ABAP_TRUE
    REPLACEMENT = '#'
    WRITE_BOM = ' '
    TRUNC_TRAILING_BLANKS_EOL = 'X'
    WK1_N_FORMAT = ' '
    WK1_N_SIZE = ' '
    WK1_T_FORMAT = ' '
    WK1_T_SIZE = ' '
    IMPORTING
    FILELENGTH =
    tables
    data_tab = I_FILE2
    FIELDNAMES =
    *& Form F_FILE_GET
    text
    -->P_P_FILEN text
    -->P_TEXT_G01 text
    FORM F_FILE_GET USING L_FILENA L_TEXT.
    CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
    DEF_FILENAME = ' '
    DEF_PATH = ' '
    MASK = ',.,*.TXT.'
    MODE = 'O'
    TITLE = L_TEXT
    IMPORTING
    FILENAME = L_FILENA
    rc =
    EXCEPTIONS
    INV_WINSYS = 1
    NO_BATCH = 2
    SELECTION_CANCEL = 3
    SELECTION_ERROR = 4
    OTHERS = 5
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Reward if helpful.
    Regards,
    Harini.S

  • How to store data from textfile to vector and delete a selected row.

    Can someone teach me how to store data from textfile to vector and delete a selected row. And after deleting, i want to write the changes in my textfile.
    Do someone has an idea? :)

    nemesisjava wrote:
    Can someone teach me how to store data from textfile to vector and delete a selected row. And after deleting, i want to write the changes in my textfile.
    Do someone has an idea? :)What's the problem? What have you done so far? What failed?
    What you described should be pretty easy to do.

  • How to Reconcile Data Between SAP Source Systems and SAP NetWeaver BI

    Hi,
    I just read "How to Reconcile Data Between SAP Source Systems and SAP NetWeaver BI".  While I'm waiting for  more authorisation to r/3 to carry it out and test this functionality.
    I'd like to ask a question to anyone who has implemented this type solution.  On page 10 it talks about creating a view then setting up the datasource. The solution talks about runnig a query.  I suspect when we run a query I would run it for only a period(using variable) to reconcile.
    My question is this.  Will the datasource extractor on /r3 only select the period in our variable or will it do a full selection of the data which would then be passed to BW for filtering?
    Regards

    DEar Mark,
    There are several avenues where you can see and reconcile your data with source system, u can see data in by tcode RSA3 for a datasource, and compare the values with actual document posted into the R/3 system. Respective fuctional consultant canhelp you a lot to confirm the data.
    On BW side u can see the data in PSA and then check tranformations which subsequent change/update/reject data records based on the selective conditions.
    hope this helps.
    Kindly assign the points if it works.
    Revert back if u need futher help/information.

  • How to extract data from SAP 4.7 and upload data to SAP ECC 6.0

    Hi,
        How to extract data from SAP 4.7 and upload data to SAP ECC 6.0? Can i use BDC,BAPI,LSMW? Help me please.

    hi
    good
    both works not possible simultaneously.
    If you want to do it in two separate task than you can use the GUI_UPLOAD function module to fulfill your requirement.
    thanks
    mrutyun^

  • How test the date formats  M/d/yyyy and MM/dd/yyyy .

    how test the date formats M/d/yyyy and MM/dd/yyyy .format should accept 3/3/1982 and 03/03/1982 dates.
    please help me

    georgemc wrote:
    kajbj wrote:
    Spoiler: Reply #3 is actually the answer to your question.Also, Bruce Willis is a ghost, the Titanic sinks and Verbal is Keyzer Soze.Only one of those endings really surprised me.
    You should've heard me in that theatre when the Titanic struck that iceberg...

  • How to get XML file using servlets that XI sent to my J2EE appl?

    Hi All!
    I have a scenario like XI sends xml file to j2ee application. In my J2EE application my servlet receives this xml. Will the xml file be in my HTTPServletRequest object? if so how to get that file from Request object.
    Please help me its urgent, Any code help is highly appreciated.
    My xml file will be like this:
    <ns0:Http_Message_Type_Demo
    xmlns:ns0="http://abcdemo.com">
    <Name>ABC</Name>
    <RollNo>123</RollNo>
    <Address>a-4</Address>
    </ns0:Http_Message_Type_Demo>
    somebody should help me!please
    Thanks

    Hi,
    You can use HTTPServletRequest object to get the XML payload.
    BufferedReader reader = request.getReader(); //gets XML payload
    String line = reader.readLine(); // to read the XML payload line by line
    (request is the HTTPServletRequest object)
    Regards,
    Uma

  • How do I initialize an array after getting xml data via httpservice?

    I am having a problem trying to initialize an array with data from an external xml file obtained via httpservice.  Any help/direction would be much appreciated.  I am using Flex 4 (Flash Builder 4).
    Here is my xml file (partial):
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Root>
        <Row>
            <icdcodedanddesc>00 PROCEDURES AND INTERVENT</icdcodedanddesc>
        </Row>
        <Row>
            <icdcodedanddesc>00.0 THERAPEUTIC ULTRASOUND</icdcodedanddesc>
        </Row>
        <Row>
            <icdcodedanddesc>00.01 THERAPEUTIC US VESSELS H</icdcodedanddesc>
        </Row>
        <Row>
            <icdcodedanddesc>00.02 THERAPEUTIC ULTRASOUND O</icdcodedanddesc>
        </Row>
    </Root>
    Here is my http service call:
    <s:HTTPService id="icdcodeservice" url="ICD9V2MergeNumAndDescNotAllCodes.xml"
                           result="icdcodesService_resultHandler(event)" showBusyCursor="true"  />
    (I have tried resultFormat using object, array, xml).
    I am using this following Tour de Flex example as the base -http://www.adobe.com/devnet-archive/flex/tourdeflex/web/#docIndex=0;illustIndex=1;sampleId =70500
    and updating it with the httpservice call and result handler.  But I cannot get the data to appear - I get [object Object] instead.  In my result handler code  I use "icdcodesar = new Array(event.result.Root.Row);"  and then "icdcodesar.refresh();".
    The key question is: How to I get data from an external xml file into an array without getting [object Object] when referencing the array entries.  Thanks much!
    (Tour de Flex example at http://www.adobe.com/devnet-archive/flex/tourdeflex/web/#docIndex=0;illustIndex=1;sampleId =70500  follows)
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   xmlns:local="*"
                   skinClass="TDFGradientBackgroundSkin"
                   viewSourceURL="srcview/index.html">
        <fx:Style>
            @namespace s "library://ns.adobe.com/flex/spark";
            @namespace mx "library://ns.adobe.com/flex/mx";
            @namespace local "*";
            s|Label {
                color: #000000;
        </fx:Style>
        <fx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                private var names:ArrayCollection = new ArrayCollection(
                    ["John Smith", "Jane Doe", "Paul Dupont", "Liz Jones", "Marie Taylor"]);
                private function searchName(item:Object):Boolean
                    return item.toLowerCase().search(searchBox.text) != -1;
                private function textChangeHandler():void
                    names.filterFunction = searchName;
                    names.refresh();
                    searchBox.dataProvider = names;
                private function itemSelectedHandler(event:SearchBoxEvent):void
                    fullName.text = event.item as String;   
            ]]>
        </fx:Script>
        <s:layout>
            <s:HorizontalLayout verticalAlign="middle" horizontalAlign="center" />
        </s:layout>
        <s:Panel title="Components Samples"
                 width="600" height="100%"
                 color="0x000000"
                 borderAlpha="0.15">
            <s:layout>
                <s:HorizontalLayout horizontalAlign="center"
                                    paddingLeft="10" paddingRight="10"
                                    paddingTop="10" paddingBottom="10"/>
            </s:layout>
            <s:HGroup >
                <s:Label text="Type a few characters to search:" />
                <local:SearchBox id="searchBox" textChange="textChangeHandler()" itemSelected="itemSelectedHandler(event)"/>
            </s:HGroup>
            <mx:FormItem label="You selected:" >
                <s:TextInput id="fullName"/>
            </mx:FormItem>
        </s:Panel>
    </s:Application>

    Hello,
    Instead of extracting the first zero element from the vid array, you should take that out and connect it allone.
    Attachments:
    init.bmp ‏339 KB

  • Hi How to get XML file from servlet that XI sent to my J2EE appl?

    Hi All!
    I have a scenario like XI sends xml file to j2ee application. In my J2EE application my servlet receives this xml. Will the xml file be in my HTTPServletRequest object? if so how to get that file from Request object.
    Please help me its urgent, Any code help is highly appreciated.
    My xml file will be like this:
    <ns0:Http_Message_Type_Demo
    xmlns:ns0="http://abcdemo.com">
    <Name>ABC</Name>
    <RollNo>123</RollNo>
    <Address>a-4</Address>
    </ns0:Http_Message_Type_Demo>
    somebody should help me!please
    Thanks

    Hi,
    You can use HTTPServletRequest object to get the XML payload.
    BufferedReader reader = request.getReader(); //gets XML payload
    String line = reader.readLine(); // to read the XML payload line by line
    (request is the HTTPServletRequest object)
    Regards,
    Uma

  • How can I get xml data from KM?

    Hi guys,
    how can i get a xml data from KM?
    I saved an xml document in KM, and I want to read its content. How can I get this document?
    Using
    DocResource = (IResource) resFactory.getResource(RID.getRID("Document/ Path"),resContext)?
    I want to know which kinds of API of KM are responsible for this.
    Thanks in advance
    Regards,
    Liying

    Hi Liying
    use this code.
    try {
                   IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
                   IUser sapUser = wdClientUser.getSAPUser();
                   com.sapportals.portal.security.usermanagement.IUser ep5User =
                        WPUMFactory.getUserFactory().getEP5User(sapUser);
                   IResourceContext resourseContext = new ResourceContext(ep5User);
                   IResourceFactory resourseFactory = ResourceFactory.getInstance();
                   RID pathRID =
                        RID.getRID(
                             "/documents/"(Path to folder where ur file is"");
                   ICollection collection =
                        (ICollection) resourseFactory.getResource(
                             pathRID,
                             resourseContext);
                   IResourceList resourceList = collection.getChildren();
                   IResourceListIterator resourceListIterator =
                        resourceList.listIterator();
    while (resourceListIterator.hasNext()) {
                        com.sapportals.wcm.repository.IResource resource =
                             resourceListIterator.next();
    try {
                             /*File from KM Reading*/
                             InputStream in = resource.getUnfilteredContent().getInputStream();
                             ByteArrayOutputStream out = new ByteArrayOutputStream();
                             byte[] buffer = new byte[4096];
                             int bytesread = 0;
                             while ((bytesread = in.read(buffer)) != -1) {
                                  out.write(buffer, 0, bytesread);
                             String dataToBeConvertedToXML = out.toString();
    catch(Exception e){}
    catch(Exception e){}
    Award points if found usefull.
    I suppose you have used KM sharing reference in ur application
    Regards
    BP

  • How to get XML value using servlet?

    how to get values from a XML file using servlet ? Thank you.
    for example: how can I get the location value (aaa) from this XML file?
    abc.xml:
    <business>
    <location>aaa</location>
    </business>

    Try to use XML Parsers to do the job.
    Use DOM or SAX Parsers that are freely available.
    Some of the popular ones are xerces, DOM, SAX.

Maybe you are looking for

  • How do I know my range expander is working?

    My range expander is set up witd the same SSID and security as my router.  I can telnet into the device, but the wireless signal has not improved where the range expander is placed. My son's xbox is about 20ft from the expander, and the "number of ba

  • Device malfunctioned

    When I plug my iPod Nano 3rd generation into my computer it says; "One of the USB devices attached to this computer has malfunctioned, and windows does not recognise it. Also the screen it black and restarting it doesn't work. When I turn on iTunes n

  • Icloud working, itunes working on the laptop with pw...however i still cannot do my updates on my phone when entering my pw..

    Cannot not update the apps on the iphone 4s entering my pw manually.  My password works on the laptop and I can sync no problem.

  • Using older firewire external drive

    I recently got a new 21.5 iMac and want to hook up and older external drive from om older iMac (the one that looks like the PIXAR lamp). The drive is an Apple drive. I bought a new 800/400 cable and tried to connect it. Nothing shows on the desktop o

  • Hi I am wondering if someone could help me with an app

    Hi I have a Casio Ravine one the first one.  I downloaded Opera mini on it a while back and was using it and liked it and then I removed it for a bit but then now after I removed it I can not get it back on my phone again could someone help me out wi