• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve inner XML & convert into String

 
Ash Shri
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking to get the inner xml as String type from the XML file.

for e.g.
<xml version = "1.0">
<Root>
<Child1>abc</Child1>
<Child2>xyz</Child2>
<ChildN>bcd</ChildN>
</Root>

I am looking to get the inner xml of <Root> node as String like -
String s = "<Child1>abc</Child1>
<Child2>xyz</Child2>
<ChildN>bcd</ChildN>"

Is it possible to do it through JAX-B or should I get it through some XML parser. If the XML is a large file with around 300 <ChildN> nodes, would it impact the performance in case of parsing it.

Could you please help with the code snippet, if possible.

Thanks in advance.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If all you want is the text between the <root> and </root> lines that is not an XML problem at all but a text file reading one.

Open the file with a reader, read line by line, start writing content to a string buffer when you pass the opening Root tag and repeat til you hit the closing tag.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic