How to read from a xml file(in String format) using a java program

hi friends
i have a string , which is xml format. i want read the values and display it.can any one suggest how to read a xml file of string format using a javaprogram

        final DocumentBuilder db =  DocumentBuilderFactory.newInstance().newDocumentBuilder();      
        final InputStream documentStream = new ByteArrayInputStream(documentXMLSourceString.getBytes("utf-8"));
        final Document document = db.parse(documentStream);

Similar Messages

  • How to read and write Xml file at client side using JavaScript !

    i am new to javascript.
    I have requirement to read and update XML file at client side.
    Will you please guide what could be the best way to read and update XMl file using javascript.

    This is a Java forum,not a Javascript forum. Maybe you should ask here [|].

  • Crystal Report that reads from an XML file Datetime or Date

    I have a Crystal Report 2008 that reads from an XML file, the source File XML Date data looks like this: 2008-03-10
    But the Crystal Report interpreted by datatime, I need the Crystal Report to look like this: 2008/03/10 (date) not 2008-03-10T00:00:00-05:00 (datatime)
    Look at an example (source file xml, report, and parameter file to execute report) at url:
    Import the file in the design and will to verify that interpret incorrectly the fields of type date as datetime
    not mapped currently for fields..

    You could always reformat the field to only display the date portion:
    Format Field > Date and Time tab; choose the date style you need here.
    Or create a formula to extract just the date and use this field in your report:

  • How to Read and Generate XML file from java code.

    hi guys,
    how to read the xml file (Condition :we know only DTD or Shema only).
    How to Generate the new xml file ?(using Shema )
    And one more how directly Generate the xml from DB?
    Pleas with code or any URL

    Using XMLbeans you can generate Java objects from an XSD schema (perhaps DTDs aswell)
    Then you can create an instance of the Document object and ask it to write itself.
    This will create an XML document complient to the schema.
    XMLBeans generates a "type" safe DOM where you can only ever have a structure compilent to you schema.

  • How to read back a xml file

    hi all
    I have a problem reading back an xml file.
    What I want to do is to store sensors and some vi parmaters.
    To do it, I put the parmaters in a cluster, flaten it to xml and then write the xml file.
    till here, no problem.
    When I want to read back the xml file, it doesn't work with the way I do (I use unflaten and read xml file)
    The datas i read back are not those I want to take back from my xml file.
    Can somebody help me with this point?
    The 7 datas filed are :
    Please help me with this, I cant do anything till this problem is solved.
    Thanks in advance for your help.
    ps : hereafter, the xml file i have written with labview. (I have put it in .txt to be sure the upload works.)
    put it back in test.xml to wok whith it.
    test.txt ‏1 KB

    there are two examples in Help >> Example Finder >> Fundamentals >> File Input and Output. One is Write Data to XML File and the other is Red Data from XML File. The first will write it and the second will read it back.
    I expanded th example with the String data and the value provided in your post and it work even with the '/' in the data.Message Edited by waldemar.hersacher on 04-06-2005 11:23 PM
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions

  • How to read from a text file one character at a time?

    I wish to read from a text file in a for loop and that on every iteration i read one charachter and proceed to the next one.
    can anyone help me?

    lava wrote:
    I wish to read from a text file in a for loop and that on every iteration i read one charachter and proceed to the next one.
    can anyone help me?
    Some additional comments:
    You really don't want to read any file one character at a time, because it is highly inefficient. More typically, you read the entire file into memory with one operation (or at least a large chunk, if the file is gigantic) and then do the rest of the operations in memory.  One easy way to analyze it one byte at a time would be to use "string to byte array" and then autoindex into a FOR loop, for example.
    Of course you could also read the file directly as a U8 array instead of a string.
    Message Edited by altenbach on 06-10-2008 08:57 AM
    LabVIEW Champion . Do more with less code and in less time .

  • How to read an external XML file in a indesign Plugin?

    Hi All,
    Can you please guide in reading an external XML file in a indesign Plugin in MAC system. I am an windows user.We are using this file for reading some inputs.

    Hello Daniel,
    I am uncertain about the actual question. If you are developing a plug-in or otherwise interfacing with the guts of ID, I suggest asking the question in the SDK forum:
    InDesign SDK Forum
    Otherwise, what is it you are wanting to know concerning importing XML into InDesign?

  • How to deploy the web.xml file when trying to use the JSP SDK from SAP?

    I want to use the adduser.jsp which downloaded form SAP SDK samples to add user in BO, but I cannot run it sucessfully. I believe it's caused the web.xml file was not deployed appropriately.
    could you please teach how to deploy the web.xml file for the JSP samples ?
    Could you show me some sample of web.xml for the SDK jsp files? Thank you very much!

    Ensure that you have followed below directory structure while deploying your web application.
    web.xml must be placed in WEB-INF. Ensure that you have included all the jar files and other necessary files in your application.
    For more information refer to the below link:

  • How to read a incorrect XML file using file adapter

    I have a XML file which is incorrect,
    <?xml version='1.0' encoding='UTF'?>
    now we can see that the XML data *<empname123>yatan</empname>* is incorrect,
    so if we have to read this type of XML in BPEL is it possible to read it or can we read it with some work around
    I have tried one way to achieve this,
    I read this XML with file adapter opaque read operation, and inside the BPEL process used Base64Decoder (Java embedding) to decode the
    opaque data to XML, it works to some extend. I am able to see the only the data like,
    100 yatan
    If I read a correct XML with same approach the data is a complete XML like,
    <?xml version='1.0' encoding='UTF-8' ?>
    can some one advice me how to achieve this, or some one has done this before

    What initially I have thought is,
    once a incorrect file comes in this failed directory, some BPEL process should get invoked and feed the data to user, for this I thought of designing a BPEL process which will poll this failed directory, so for this we will need a empty BPEL process which will pick the file and then pass the data, the issue is I need to use here a opaque read and I dont know how to convert back the opaque (faulty XML) back to string.
    I have already tried to convert the opaque to XML using java embedding but for faulted XML only the data comes back in the form of string, where as need the complete XML back, can you suggest how to do this.

  • How to Read,Write & Update XML File

    How to read,create and update an XML file using DOM

    xml API's are there like jdom and stuffs...
    search in google : xml API's + java

  • How to read from MS  Excel file ?

    Which is the best way to read from a MS Excel file ?
    I need to read both "column-wise" and "row-wise".
    Is there any free software or java api which does this. I have come across some paid softwares which do that, but i would prefer using something which is free.
    I have tried using the "save as" option to save as tab delimited, comma delimited, unicode text ... but they raise too many exceptions, and cannot be read as we read a normal text file.
    Please do suggest.
    If you would search of the forums, you would find these two threads, and probably many others. They not only include pointers to what you ask but discussions of the pros and cons among various solutions.

  • Reading from an xml file

    Hi All,
       I want to read an xml file and add that many checkboxes with the names specified in xml.
    Can anybody please share a working sample code please

    If this post answers your question or helps, please mark it as such.
    Greg Lafrance - Flex 2 and 3 ACE certified
    Flex / AIR Development, Training, and Support Services
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="">
      <mx:XML id="xml" source="data1.xml"/> 
      <mx:XMLListCollection id="xlc" source="{xml..item}"/>
      <mx:Repeater id="rp" dataProvider="{xlc}">
        <mx:CheckBox label="{rp.currentItem}"/>
    <?xml version="1.0" encoding="utf-8"?><items>

  • How to read from 2 data files ?

    I'm trying to create a program that will read data from two dat files that are linked by a reference code in each file.
    I have been using StringTokenizer to read from one file as follows:
    but the problem is that the dat files contain int, String and double values.
    import java.util.StringTokenizer;
    public class Student
         public static void main(String[]args)
         String file = "CourseWork.dat";//Locate the file to open
         String input;     // to be used to identify each line of text
         String word;     // used to identify each word in the text
         StringTokenizer tokenizer;//value of StringTokenizer
         BufferedReader fin =;
         input = fin.readLine;          
         while (input !=null)          
                   tokenizer = new StringTokenizer (input);
                   while (tokenizer.hasMoreTokens())                {                                                                                               word = tokenizer.nextToken();
                   input = fin.readLine();
    Any pointers greatly appreciated

    read all of them to a StringBuffer,
    then stoken.
    Pivotonic Inc.
    1. java IDE tool : JawaBeginer
    2. java jar tool : JavaJar

  • How to align a raw Xml file tag by tag using java

    Hi All,
    Can any one please help me in writing a java code(jdk1.3) ,which will format a raw xml file and keep the formated data in a string object.

    Ex File:
    expected format:
    Can anyone help me on preparing logic using core java ???

  • Map attributes of XML file to ABAP table, using a XSLT program

    Hi dear Gurus.
    I have to transfer the information from the XML's element attributes to abap internal tables and store that information.
    Somebody has a clear sample to do this data transfer.
    I found a clas iXML, do you have a sample to read the elements and attributes using this class?
    Thanks in advance.

    hello ,
    search for BCCIIXM* in se38.

Maybe you are looking for