0

I have a SOAP message as a String and need to parse it in Java. I receive an XML file containing the data and the signature of the XML data content as a separate XML part of the same soap message The following is a sample SOAP Message(is not a valid xml) i receive:

------=_Part_2074_1202079654.1337767440483
Content-Type: text/xml; charset=utf-8
Content-Transfer-Encoding: binary
Content-Id: <164914372224.1337767440483.IBM.WEBSERVICES@su79aas2.pinkroccade.lan>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Header/>

<soapenv:Body>

<FileSet xmlns="http://www.mydomain.com">
<FileSetId>SRQ</FileSetId>
<File>
<FileType>SRQACK</FileType>
<FileName>ACK-BSP2-BP2-20120523100300-01.xml</FileName>
<FileContentId>1</FileContentId>
</File>
<File><FileType>SRQSIG</FileType>
<FileName>SIG-BSP2-BP2-20120523100300-01.sig</FileName>
<FileContentId>2</FileContentId>
</File>
</FileSet>

</soapenv:Body>
</soapenv:Envelope>
------=_Part_2074_1202079654.1337767440483
Content-Type: text/xml; charset=utf-8
Content-Transfer-Encoding: binary
Content-Id: 1

<?xml version="1.0" encoding="UTF-8"?>
<!--Handle SRQACK, SRSMUT, SUMMUT BP Postbank version 1.1-->
<Acknowledgements xmlns="http://www.mydomain.com">
<Header>
<BatchId>ACK-BSP2-BP2-20120523100300</BatchId>
<InterfaceId>ACK</InterfaceId>
<Version>02.0</Version>
<SourceSystemId>BSP2</SourceSystemId>
<TargetSystemId>BP2</TargetSystemId>
<CreateDateTime>2012-05-23T10:03:00Z</CreateDateTime>
<MessageCount>4</MessageCount>
</Header>
<Acknowledgement>
<BatchId>SRQ-BP2-BSP2-20120416101400</BatchId>
<AckTimeStamp>2012-05-23T10:03:00Z</AckTimeStamp>
<Result>ERROR</Result>
<ReasonCode>107</ReasonCode>
</Acknowledgement>
<Acknowledgement>
<BatchId>SRQ-BP2-BSP2-20120514140516</BatchId>
<AckTimeStamp>2012-05-23T10:03:00Z</AckTimeStamp>
<Result>OK</Result>
</Acknowledgement>
<Acknowledgement>
<BatchId>SRQ-BP2-BSP1-20120514140511</BatchId>
<AckTimeStamp>2012-05-23T10:03:00Z</AckTimeStamp>
<Result>ERROR</Result>
<ReasonCode>112</ReasonCode>
</Acknowledgement>
<Acknowledgement>
<BatchId>SRQ-BP2-BSP3-20120514140520</BatchId>
<AckTimeStamp>2012-05-23T10:03:00Z</AckTimeStamp>
<Result>ERROR</Result>
<ReasonCode>112</ReasonCode>
</Acknowledgement>
</Acknowledgements>

------=_Part_2074_1202079654.1337767440483
Content-Type: text/xml; charset=utf-8
Content-Transfer-Encoding: binary
Content-Id: 2

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--Handle SRQSIG, SRSSIG, EXCSIG, SUMSIG BSP 2 Biller version 1.2-->
<nl:Signature xmlns:nl="http://www.mydomain.com">
<SignatureValue>lJw2CNdcgEGEychSH/snpMvnXrV91775UANSZGN23n7hQnlIiak8Dqr9pe6FAtLjkZ9UZPip26VTxGVzeCHdsgYwrLt3mTLfX0h6KeRhPCYGd9QLxok1yv0Ua6iNlP0oEPaE4t6wJw/CKfCua4W0Jbnm18Ym5J7U08YB1+rc4Lw=</SignatureValue>
<Fingerprint>166105D2F2F23663F4405B6D84A4F51B48907F77</Fingerprint>
</nl:Signature>

------=_Part_2074_1202079654.1337767440483--

2 Answers2

0

The first part is to extract valid (from XML perspective) fragments from your text.

You will have to do the first part manually (= write your own code) or if you are lucky you may find a library which will do it for you.

The second part - feed those fragments to the DOM parser you use.

Alex Kreutznaer
  • 1,170
  • 8
  • 18
0

Use a multi-line regular expression to pull out <ackowledgements*.</ackowledgements>and another to pull out <nl:Signature.*<\nl:Signature> and feed those two strings into your dom parser of choice - for an example of how to do that, see In Java, how do I parse XML as a String instead of a file?

Community
  • 1
  • 1
Steve Atkinson
  • 1,219
  • 2
  • 12
  • 30
  • i could have tried that, but the problem is in the first part: i dont know what `XML root tag` i will get from a SOAP Message. I can get `` tag or any other root tag. this will however work for the second part, though. – cannot_mutably_borrow Jan 21 '13 at 11:23
  • your root tag will be the first one after so you use a regex to pull out the whole and parse that, then pull out the 1st childof Body from your dom model which will give you your root. – Steve Atkinson Jan 21 '13 at 18:50