trudyhlittle
asked on
Access embeded encoded XML document in another XML document
I have an XML document (SOAP message) that contains an XML document that is encoded. I need to be able to access the information in the embeded document as I would any other XML document.
Example I have the following document. The PostMessageResult element contains an encoded XML document. I want to be able to access each element of embeded document as part of the larger document but when I create my DOM object, the XML document is just a text value of my element. How do I decode the embeded XML document so that when I create my DOM object the XML document is included as part of the XML document not as text but as nodes?
I have this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<PostMessageResponse xmlns="https://secure.CompanyName.com"> <PostMessageResult><Com panyName&g t;<Stat usCode> 0</Stat usCode> <Status Message> ;Success&l t;/StatusM essage> <Respon seXML>& lt;Company Name CompanyNameID="3241553" SourceID="1000" DestinationID="1077" TransDate="10/21/2004 8:06:26 AM"><Transaction TransactionID="4052836"> ;<Messa ge> <MessageType>Message _Confirmat ion</Me ssageType& gt;<Sou rceBusines sRef>63 650</So urceBusine ssRef>& lt;SourceR outingRef& gt;</So urceRoutin gRef> <SourceLoanNumber>&l t;/SourceL oanNumber& gt;<Des tinationBu sinessRef& gt;04-1717 </DestinationBusinessRe f><D estination RoutingRef > </DestinationRoutingRef > <DestinationLoanNumber& gt;</De stinationL oanNumber& gt;<Add itionalInf o>Messa ge entered into CMS successfully.</Addition alInfo> </Message></Trans action> </CompanyName></R esponseXML ></C ompanyName >
</PostMessageResult>
</PostMessageResponse>
</soap:Body>
</soap:Envelope>
I want this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body>
<PostMessageResponse xmlns="https://secure.CompanyName.com">
<PostMessageResult>
<CompanyName>
<StatusCode>0</StatusCode>
<StatusMessage>Success</St atusMessag e>
<ResponseXML>
<CompanyName CompanyNameID="3241553" SourceID="1000" DestinationID="1077" TransDate="10/21/2004 8:06:26 AM">
<Transaction TransactionID="4052836">
<Message>
<MessageType>Message_Confi rmation</M essageType >
<SourceBusinessRef>63650</ SourceBusi nessRef>
<SourceRoutingRef></Source RoutingRef >
<SourceLoanNumber></Source LoanNumber >
<DestinationBusinessRef>04 -1717</Des tinationBu sinessRef>
<DestinationRoutingRef></D estination RoutingRef >
<DestinationLoanNumber></D estination LoanNumber >
<AdditionalInfo>Message entered into CMS successfully.</AdditionalI nfo>
</Message>
</Transaction>
</CompanyName>
</ResponseXML>
</CompanyName>
</PostMessageResult>
</PostMessageResponse>
</soap:Body>
</soap:Envelope>
Thanks.
Example I have the following document. The PostMessageResult element contains an encoded XML document. I want to be able to access each element of embeded document as part of the larger document but when I create my DOM object, the XML document is just a text value of my element. How do I decode the embeded XML document so that when I create my DOM object the XML document is included as part of the XML document not as text but as nodes?
I have this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<PostMessageResponse xmlns="https://secure.CompanyName.com"> <PostMessageResult><Com
</PostMessageResult>
</PostMessageResponse>
</soap:Body>
</soap:Envelope>
I want this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body>
<PostMessageResponse xmlns="https://secure.CompanyName.com">
<PostMessageResult>
<CompanyName>
<StatusCode>0</StatusCode>
<StatusMessage>Success</St
<ResponseXML>
<CompanyName CompanyNameID="3241553" SourceID="1000" DestinationID="1077" TransDate="10/21/2004 8:06:26 AM">
<Transaction TransactionID="4052836">
<Message>
<MessageType>Message_Confi
<SourceBusinessRef>63650</
<SourceRoutingRef></Source
<SourceLoanNumber></Source
<DestinationBusinessRef>04
<DestinationRoutingRef></D
<DestinationLoanNumber></D
<AdditionalInfo>Message entered into CMS successfully.</AdditionalI
</Message>
</Transaction>
</CompanyName>
</ResponseXML>
</CompanyName>
</PostMessageResult>
</PostMessageResponse>
</soap:Body>
</soap:Envelope>
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What you need to do is to do that again. You should build an InputSource the second time from the
node that represents the embedded document
node that represents the embedded document
Hang on - just looking again - that was wrong
why dont you just do this:
whatYouHave = whatYouHave.replaceAll("&l t;", "<");
whatYouHave = whatYouHave.replaceAll("&g t;", ">");
?
why dont you just do this:
whatYouHave = whatYouHave.replaceAll("&l
whatYouHave = whatYouHave.replaceAll("&g
?
Hang on again - think i was right both times ;-)
You need to apply my second comment first (to the node as String) and my first second ;-)
You need to apply my second comment first (to the node as String) and my first second ;-)
ASKER
Thanks for the input. I actually only needed to do your first suggestion. Creating another document using the embeded xml automatically decoded the document.
I think I might have been able to do your second suggestion on the whole document and then create only one document, but the first one worked, so I'll quit while I'm ahead. :o)
Thanks.
I think I might have been able to do your second suggestion on the whole document and then create only one document, but the first one worked, so I'll quit while I'm ahead. :o)
Thanks.
8-)
>>Creating another document using the embeded xml automatically decoded the document.
Yes i thought that might happen.
btw, it doesn't matter hugely, but for future reference, it's better to try to mark the comment that's closest to the
actual answer as the 'accepted' one for future viewers
>>Creating another document using the embeded xml automatically decoded the document.
Yes i thought that might happen.
btw, it doesn't matter hugely, but for future reference, it's better to try to mark the comment that's closest to the
actual answer as the 'accepted' one for future viewers
ASKER
I know, sorry. I meant to select your first suggestion but I grabbed the first response instead and obviously didn't take the time to read the screen before I rated it. My bad. I'll be more careful next time.
No problem ;-)
ASKER
Here is the code I'm using to create the Document object. buffer is a variable that holds a string retrieved from the database that looks like the first example above (under the "I have this:" text).
DocumentBuilderFactory factory = DocumentBuilderFactory.new
factory.setNamespaceAware(
builder = factory.newDocumentBuilder
Document result = builder.parse( new InputSource( new StringReader( buffer )));