-1

I have a complex xml string that i have to parse i retrieve some data, here is the content :

<root1>
    <root2>
        <A>something</A>
        <B>something</B>
        <C>
            <D>
                <GetE>DataE</GetE>
                <GetF>DataF</GetF>
                <G>something</G>
                <H>something</H>
                <I>
                    <J>
                      <GetK>DataK</GetK>
                      <GetL>DataL</GetL>
                    </J>
                </I>
            </D>
            <D>
                <GetE>DataE</GetE>
                <GetF>DataF</GetF>
                <G>something</G>
                <H>something</H>
                <I>
                    <J>
                      <GetK>DataK</GetK>
                      <GetL>DataL</GetL>
                    </J>
                </I>
            </D>
        </C>
     </root2>
</root1>

I would like to print the content of GetE, GetF, GetK and GetL :

for example :

GetE = DataE,GetF = DataF,GetK = DataK,GetL = DataL

GetE = DataE,GetF = DataF,GetK = DataK,GetL = DataL

...

To convert my String data to an XML, I use this function In Java, how do I parse XML as a String instead of a file?

Any idea please ?

Community
  • 1
  • 1
zeomega
  • 345
  • 2
  • 6
  • 18

2 Answers2

0

First of all, check this answer that's more applicable to your case. XPath is a convenient and easy t-to-use technology to extract the information you seek, but performance requirements may dictate otherwise.

The xpath expressions, in your case, would be, for instance::

"root1/root2/C/D/GetE/text()"
"root1/root2/C/D/GetF/text()"

But as others have commented, "root1/root2/C/D/GetE" doesn't return a single node, so you have to decide how you are going to represent the information too.

Community
  • 1
  • 1
Patrice M.
  • 4,209
  • 2
  • 27
  • 36
0

Maybe there is a simpler way but SAXParser would do the job.

zrac
  • 153
  • 7