1


I have the following response from a server which is a xml(received/stored in string).

<s:Envelope xml:s='http://sada.soap.org/soap/env/'>
   <Body>
       <GetResponse xml='http://www.hotmail.msn.com/'>
          <GetResult>
              X-Originating-IP: [207.46.124.17]X-Originating-Email:X-OriginalArrivalTime: 22 Apr 2011 10:47:04.3513 (UTC) FILETIME=[9E2CE208:01CC00DA]Date: 22 Apr 2011 03:47:04 -0700 X-OIM-Sequence-Num: 2458621X-MSGR SDGML:TWVzcQo=UmFrZXN
          </GetResult>
       </GetResponse>
   </Body>
 </s:Envelope>

Now I want to get the attributes of .I guess in the above,the attributes would be X-Originating-IP,-Originating-Email,X-OIM-Sequence-Num.
I tried using DocumentBuilderFactory, but I could'nt get the attributes value.Can somebody help me with this.

TheCottonSilk
  • 8,662
  • 2
  • 26
  • 37
kiddo
  • 1,596
  • 7
  • 31
  • 60
  • If that's what the webservice returns, it's going to be a PITA to parse, as it has no structure. Just to be clear, the text that is betweeen the GetResult tags is text, not "xml" so you won't be able to use DOM to extract, for example, the X-Originating value. You need first to get what is inside GetResult and then parse that awful line manually (using regexes or whatever you want) – Augusto Apr 25 '11 at 09:20
  • Exactly,thats is what I am trying to get.I understand your point completly.I am not able to get that String value inside that tag. – kiddo Apr 25 '11 at 09:26
  • I strongly suspect that the attributes you have shown as "xml" and "xml:s" are actually "xmlns" and "xmlns:s". Otherwise, there's something very wrong with the design of the web service. – Michael Kay Apr 25 '11 at 14:23
  • @Michael,you are right..I just edited it,it is actually so long..just for the sake of better understanding I showed like that.and I tried to use proper XML parser but it is'nt working for my case.i mean the attributes within the element are not proper.I appreciate any good suggestions – kiddo Apr 25 '11 at 15:04

1 Answers1

0

I would recommend using the javax.xml.xpath APIs for this. For an example (with namespaces) see my answer to a similar question:

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400