I think maybe I'm starting to understand what you're after.  You're starting 
with a string of characters representing a serialization of an XML document, 
and you want to include it in another document.  If that's the case, you have a 
couple of choices.

One is to treat this as a simple text transformation.  Just write out the text 
of the document prolog and root element start tag, then write your input 
string, then write the element end tag.

The other is to handle the input as XML.  To do this, you'll need to parse your 
input string into a DOMDocument.  (See the DOMParse sample application for one 
way to do this.)  You'll still need to create a new document.  You'll use 
DOMDocument::importNode() to import the root node of your input document to the 
new document, and then use DOMNode::appendChild() to append the imported node 
to the root element of the new document.  Then you can serialize the new 
document.


-----Original Message-----
From: K.WIKI [mailto:[email protected]]
Sent: Thu 6/25/2009 11:32 AM
To: [email protected]
Subject: RE: Xerces and special caractere < >
 

Thanks 

This The Code

void CreaXML( CString strValue,CString strFile)  
{
        XMLCh m_xmlChTempStr[400];
        XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* m_xmlDoc;
        DOMImplementation *m_xmlImpl;
        XMLCh tempStr[400];

        XMLPlatformUtils::Initialize();

        XMLString::transcode("LS", m_xmlChTempStr, (400));
        m_xmlImpl =
DOMImplementationRegistry::getDOMImplementation(m_xmlChTempStr);
        
        CString root = "Contents";
        XMLString::transcode(root, m_xmlChTempStr, (400));
        m_xmlDoc = m_xmlImpl->createDocument(0, m_xmlChTempStr, 0);
    DOMElement* Contents = m_xmlDoc->getDocumentElement();
        
        XMLString::transcode("version", m_xmlChTempStr, (400 ));
        XMLString::transcode(VERSIO_XML_REC_CMD, tempStr, (400));
        DOMAttr* attr = m_xmlDoc->createAttribute(m_xmlChTempStr);
        attr->setValue(tempStr);
        Contents->setAttributeNode(attr);

        XMLString::transcode( m_strValue, m_xmlChTempStr, (400));
        
        try
        {
                DOMWriter *theSerializer =
((DOMImplementationLS*)m_xmlImpl)->createDOMWriter();

                //Opcional. activem (Set) el nostre propi errorHandler
                DOMErrorHandler *errorHandler = new DOMCountErrorHandler();
                theSerializer->setErrorHandler(errorHandler);

        //Opcional. set feature to serializer 
        if (theSerializer->canSetFeature(XMLUni::fgDOMWRTSplitCdataSections,
false))
            theSerializer->setFeature(XMLUni::fgDOMWRTSplitCdataSections,
false);

        if
(theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, false))
            theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent,
false);

        if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true))
            theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true);

        if (theSerializer->canSetFeature(XMLUni::fgDOMWRTBOM, true))
            theSerializer->setFeature(XMLUni::fgDOMWRTBOM, true);

                // creem un "Format target" per rebre el xml creat pel 
serialtzador 
        // StdOutFormatTarget dibuixa el xml resultant q rep del
serialitzador
                XMLFormatTarget *FormTarget = new 
LocalFileFormatTarget(m_strFile);

                // serialitzem amb DOMWriter::writeNode()
                
                theSerializer->writeNode(FormTarget, *m_xmlDoc);
                
            // std::ios_base::out est automatiquement ajouté par le
    // constructeur de std::ofstream

                theSerializer->release();
                delete errorHandler;
                delete FormTarget;

        }
        catch (const OutOfMemoryException& /*e*/)
    {
                
        }
    catch (const XMLException& /*e*/)
    {
                
    }

        nErrorSuma = nError1 + nError2;
        return nErrorSuma;

        m_xmlDoc->release();
        
}

with

//Value Of strValue =
"<Personne><FirstName>toto</FirstName><LastName>toto</LastName></Personne><Personne><FirstName>tata</FirstName><LastName>tata</LastName></Personne>"


I hops it's more clear now 

:)



Jesse Pelton wrote:
> 
> Just attach the code to a message.  I'd recommend making the simplest
> possible test case out of it first.  This has a couple of advantages:
> first, it's possible that you will find the problem yourself in the course
> of simplifying it, and second, if you do need to ask for help, the simpler
> the code is, the more likely it is that someone will be willing and able
> to help.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Xerces-and-special-caractere-%3C-%3E-tp24201194p24205593.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Reply via email to