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>&lt;CompanyName&gt;&lt;StatusCode&gt;0&lt;/StatusCode&gt;&lt;StatusMessage&gt;Success&lt;/StatusMessage&gt;&lt;ResponseXML&gt;&lt;CompanyName                   CompanyNameID="3241553" SourceID="1000" DestinationID="1077" TransDate="10/21/2004 8:06:26 AM"&gt;&lt;Transaction TransactionID="4052836"&gt;&lt;Message&gt;                  &lt;MessageType&gt;Message_Confirmation&lt;/MessageType&gt;&lt;SourceBusinessRef&gt;63650&lt;/SourceBusinessRef&gt;&lt;SourceRoutingRef&gt;&lt;/SourceRoutingRef&gt;                  &lt;SourceLoanNumber&gt;&lt;/SourceLoanNumber&gt;&lt;DestinationBusinessRef&gt;04-1717 &lt;/DestinationBusinessRef&gt;&lt;DestinationRoutingRef&gt;      &lt;/DestinationRoutingRef&gt;            &lt;DestinationLoanNumber&gt;&lt;/DestinationLoanNumber&gt;&lt;AdditionalInfo&gt;Message entered into CMS successfully.&lt;/AdditionalInfo&gt;      &lt;/Message&gt;&lt;/Transaction&gt;            &lt;/CompanyName&gt;&lt;/ResponseXML&gt;&lt;/CompanyName&gt;
                  </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</StatusMessage>
                              <ResponseXML>
                                    <CompanyName CompanyNameID="3241553" SourceID="1000" DestinationID="1077" TransDate="10/21/2004 8:06:26 AM">
                                          <Transaction TransactionID="4052836">
                                                <Message>
                                                      <MessageType>Message_Confirmation</MessageType>
                                                      <SourceBusinessRef>63650</SourceBusinessRef>
                                                      <SourceRoutingRef></SourceRoutingRef>
                                                      <SourceLoanNumber></SourceLoanNumber>
                                                      <DestinationBusinessRef>04-1717</DestinationBusinessRef>
                                                      <DestinationRoutingRef></DestinationRoutingRef>
                                                      <DestinationLoanNumber></DestinationLoanNumber>
                                                      <AdditionalInfo>Message entered into CMS successfully.</AdditionalInfo>
                                                </Message>
                                          </Transaction>
                                    </CompanyName>
                              </ResponseXML>
                        </CompanyName>
                  </PostMessageResult>
            </PostMessageResponse>
      </soap:Body>
</soap:Envelope>


Thanks.
trudyhlittleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>but when I create my DOM object, the XML document is just a text value of my element

Can you show how you're doing that?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trudyhlittleAuthor Commented:
Sorry for the delay.  Busy weekend.

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.newInstance();
factory.setNamespaceAware(false);
builder = factory.newDocumentBuilder();
Document result = builder.parse( new InputSource( new StringReader( buffer )));
0
CEHJCommented:
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
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

CEHJCommented:
Hang on - just looking again - that was wrong

why dont you just do this:

whatYouHave = whatYouHave.replaceAll("&lt;", "<");
whatYouHave = whatYouHave.replaceAll("&gt;", ">");

?
0
CEHJCommented:
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 ;-)
0
trudyhlittleAuthor Commented:
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.
0
CEHJCommented:
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

0
trudyhlittleAuthor Commented:
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.
0
CEHJCommented:
No problem ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.