Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How can I parse an XML from String?

  Asked By: Ketan    Date: Oct 03    Category: Java    Views: 748
  

How can I parse an XML from String?

I've used following code to parse XML file.
-----
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setIgnoringElementContentWhitespace(true);
factory.setIgnoringComments(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document XMLDoc = builder.parse(fileName);
-----

builder.parse(...) does not take String input... please help.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Jackson Bouchard     Answered On: Oct 03

What java version are you using?

1.4.2 has DocumentBuilder.parse(String uri);

 
Answer #2    Answered By: Isaac Williams     Answered On: Oct 03

We are using Java 1.3......................

 
Answer #3    Answered By: Luki Fischer     Answered On: Oct 03

Turn the String into a byte array and then into an input  stream, which
parse does that:

builder.parse(new ByteArrayInputStream(text.getBytes()));

 
Didn't find what you were looking for? Find more on How can I parse an XML from String? Or get search suggestion and latest updates.




Tagged: