Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
How to convert following xml string to String[]
XML
<?xml version=1.0 encoding=UTF-8 standalone=yes?>
<NewDataSet>
<WHDS>
  <WHBILL>
    <TrnDate>14-Oct-2014</TrnDate>
    <FromDate>01-Oct-2014</FromDate>
    <ToDate>31-Oct-2014</ToDate>
    <Location>Gujarat</Location>
    <ClientCode>1001</ClientCode>
    <ClientName>abc</ClientName>
    <WarehouseCode>g001</WarehouseCode>
    <WarehouseName>g1</WarehouseName>
    <ServiceTaxApplicable>y</ServiceTaxApplicable>
    <RefVouchNo>1</RefVouchNo>
    <StorageCharges>2000</StorageCharges>
  </WHBILL>
</WHDS>
</NewDataSet>


[EDIT]
Java
 String xmlString;
Document doc=getDomElement(xmlString);

public Document getDomElement(String xml) {
        Document doc = null;
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xml));
            doc = db.parse(is);

        } catch (ParserConfigurationException e) {
            Log.e("Error: ", e.getMessage());
             return null;
        } catch (SAXException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        } catch (IOException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        }
        return doc;
    }

[/EDIT - content moved from comment]
Please Help me.
Posted
Updated 16-Mar-15 3:39am
v2
Comments
Maciej Los 16-Mar-15 8:30am    
Why?
Sid_Joshi 16-Mar-15 8:33am    
I want to transfer data from server to android app.
Maciej Los 16-Mar-15 8:51am    
What have you tried?
Sid_Joshi 16-Mar-15 8:53am    
--- content has been moved to the question ---
Maciej Los
Sergey Alexandrovich Kryukov 16-Mar-15 14:19pm    
Right question. However, I put a basic answer, please see. I guess, the inquirer really needs right idea first. Instead of dealing with that string[]... :-)
—SA

1 solution

 
Share this answer
 
Comments
Sid_Joshi 17-Mar-15 9:15am    
Your solution is correct Mr. Maciej Los. but in my case xml string will came from web service and it will available in String format and not xml resource.
Maciej Los 17-Mar-15 9:20am    
You did not mentioned that in your question. If you say that the answer is correct, i'd suggest you to accept it (green button). I suggest you to post another question. Posting new question, be careful with the description...
Sid_Joshi 17-Mar-15 9:23am    
Sorry, but I described this in comment. don't worry I will solve this problem.
Maciej Los 17-Mar-15 9:24am    
Sorry, i missed that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900