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?

earthmover
  • 4,395
  • 10
  • 43
  • 74
zorox
  • 27
  • 1
  • 6
  • 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... – Jon Skeet Jul 04 '14 at 12:51
  • I written but it did dot seem proper. Suppose that it is proper xml – zorox Jul 04 '14 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. – Jon Skeet Jul 04 '14 at 12:55

1 Answers1

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 ) ) ); 
Nadendla
  • 712
  • 2
  • 7
  • 17