xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott_B...@lotus.com
Subject Re: Embedding XML within XML Problem
Date Wed, 04 Apr 2001 21:44:18 GMT

> QUESTION 1:
> Is there a better way to handle this situation of embedding an XML
> document, and later retrieving it?

I don't see why you are creating a CDATA section... why not just embed the
subtree as XML in <Message_type>?  Do something like <xml:copy-of select
="document(http://myExternalDoc.xml)"/>.  This should copy CDATA sections
intact.

> Moreover, what is the most efficient way of converting a whole
> Document() into a String? I do not know how to do this, e.g.

Try something like:

public String convertNodeToXMLString(Node node)
{
      // Set up an identity transformer to use as serializer.
      Transformer serializer = TransformerFactory.newInstance
().newTransformer();
      serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
// just an example
      java.io.StringWriter swriter = new java.io.StringWriter();
      serializer.transform(new DOMSource(myNode), new StreamResult(swriter
));
      String myXMLString = swriter.toString();
      return myXMLString ;
}

This conversation should probably be on xalan-dev.

-scott




                                                                                         
                            
                    Arvind Bassi                                                         
                            
                    <arvind_bassi@ya        To:     general@xml.apache.org            
                               
                    hoo.co.uk>              cc:     (bcc: Scott Boag/CAM/Lotus)       
                               
                                            Subject:     Embedding XML within XML Problem
                            
                    04/04/2001 01:22                                                     
                            
                    PM                                                                   
                            
                    Please respond                                                       
                            
                    to general                                                           
                            
                                                                                         
                            
                                                                                         
                            




There are two questions located at the base of this email.

The project that l am working on at present, has the following flow:

1. Obtain external XML
2. Transform external XML to internal XML format, with external XML
embedded inside internal XML
3. Process transaction inside internal XML document (as part of this
store the external XML document embedded inside)
4. Obtain query results from database and produce an internal XML
document
5. Transform this internal XML document to an external XML format
6. Send external XML

I am using Xalan-J, and my parser is Xerces-J which ships with it.

I have handled (or tried to handle) the embedding and extraction of the
external XML as so:

1. I have embedded the external XML inside a tag called <Message_type>.
The external XML is wrapped inside a CDATA Section.
2. I have tried to extract the CDATA section using Xerces-J.

However, when Xerces-J encounters the CDATA Section it treats the
opening CDATA clause as a Node.PROCESSING_INSTRUCTION_NODE, aswell as
the closing CDATA clause. The embedded XML document is treated like a
document fragment, and thus l would need to iterate through it and use
code to generate a String from it.

Therefore, this has come to an impasse.

QUESTION 1:
Is there a better way to handle this situation of embedding an XML
document, and later retrieving it?

QUESTION 2:
Moreover, what is the most efficient way of converting a whole
Document() into a String? I do not know how to do this, e.g.

    public String getStringFromDocument(Document doc){

        String s = null;

        ???????????? s = doc ?????????????

        return s;
    }

I was wondering if l can transform the whole Document() into a String,
then l could use String manipulation methods to isolate the CDATA
Section and extract the original XML document as a String.

____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org






---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message