[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Java XML getting Element content as String

Posted on 2009-12-27
3
Medium Priority
?
586 Views
Last Modified: 2013-12-29
I have an XML document that looks like this:
<Penny>
      <Script id="CustomTEST1" ExID="CustomTEST1">
            <Priority>URGENT</Priority>            
                 Ping 152.22.34.12
            <QBE stamp="305419896">
                  <QPT Iterations="200" NumberOfPackets="100" TimeBetweenTrains="1" Destination="147.27.14.8"
                  PacketSize="60" Protocol="ICMP" Tos="0" TTLs="50" SourcePort="7777" DestinationPort="7777"/>
            </QBE>
      </Script>
</Penny>

I want to get everything in the "script" element as one String.
 I can't use getTextContent() because that only returns the text content of the element as a String, so it would only return "URGENT                 Ping 152.22.34.12" in this case, where as I want a text String that would read:

"<Priority>URGENT</Priority> Ping 152.22.34.12<QBE stamp="305419896">      <QPT Iterations="200" NumberOfPackets="100" TimeBetweenTrains="1" Destination="147.27.14.8"                   PacketSize="60" Protocol="ICMP" Tos="0" TTLs="50" SourcePort="7777" DestinationPort="7777"/>      </QBE>"

How do I go about doing that?
Thanks
0
Comment
Question by:bored_shiva
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 1000 total points
ID: 26129454
0
 

Author Closing Comment

by:bored_shiva
ID: 31670193
This rocks, exactly what I was looking for. Thanks.
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26130046
thanks :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month18 days, 17 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question