Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access embeded encoded XML document in another XML document

Posted on 2004-10-22
9
Medium Priority
?
204 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:trudyhlittle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 12384985
>>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
 

Author Comment

by:trudyhlittle
ID: 12411610
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12411911
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 12411961
Hang on - just looking again - that was wrong

why dont you just do this:

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

?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12411993
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
 

Author Comment

by:trudyhlittle
ID: 12413801
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12413851
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
 

Author Comment

by:trudyhlittle
ID: 12413906
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12413921
No problem ;-)
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question