• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieve inner XML & convert into String

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
It was the best of times. It was the worst of times. It was a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic