0

Hello I have generated XML content as string. But I have to convert string to XML data type.

String str = "<?xml version="1.0" encoding="utf-8"?><Message><Rc1>12343322</Rc1><Rc2>125145552</Rc2><Rc3>54682242</Rc3><Rc4>7777332287</Rc4></Message>"

How can I convert this string to xmldoc type?

3
  • What have you tried so far? Are you trying to use the W3C API in Java? Have you looked up XML tutorials? Note that "1234...287" is not XML... Commented Jul 4, 2014 at 12:51
  • I written but it did dot seem proper. Suppose that it is proper xml Commented Jul 4, 2014 at 12:54
  • Well, that's now not a valid string literal. But okay, assuming you have a String which does contain valid XML... what have you tried so far? There are lots of tutorials on the web for parsing XML in Java. You should do research before asking a question - and if you have done research and have tried something, but it's not working, provide sample code and explain what's going wrong. Commented Jul 4, 2014 at 12:55

1 Answer 1

0
  String xmlStr = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Message><Rc1>12343322</Rc1>     <Rc2>125145552</Rc2><Rc3>54682242</Rc3><Rc4>7777332287</Rc4></Message>"
 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();  
  DocumentBuilder builder = factory.newDocumentBuilder();  
  Document doc = builder.parse( new InputSource( new StringReader( xmlStr ) ) ); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.