Hi,

thank you.  I will try what you have told me.

thank you very much.

-dh

-----Original Message-----
From: Gareth Reakes [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 02, 2002 8:30 AM
To: [EMAIL PROTECTED]
Subject: RE: Serialize and unserialize DOMDocument over socket


Hi,
        The problem is 2 fold. First you have not set the namespaces 
feature on DOMBuilder to true - do that like this:

        pDOMBuilder->setFeature(X("namespaces"), true);

secondly you are mixing level 1 and level 2 creation methods. 
createDocument uses level 2 (createElementNS) and therefore it will not 
compare correctly with localName if you then create it with level 1. 
Prefer using createXXXNS.


Gareth




On Tue, 1 Oct 2002, Dave Hoffer wrote:

> Hi Gareth,
> 
> //Here is the code that makes the DOM document...
> IMessage::FillDoc()
> {
>       DOMImplementation* impl =  
>DOMImplementationRegistry::getDOMImplementation(L"Core");
> 
>       m_pDomDocument = impl->createDocument(
>                               0,                    // root element namespace URI.
>                               WSZ_MSG_ROOT,         // "ATDNewsCLSMsg" root element 
>name
>                               0);                   // document type object (DTD).
> 
>       DOMElement* rootElem = m_pDomDocument->getDocumentElement();
> 
>       DOMElement* msgElem = m_pDomDocument->createElement(WSZ_HEADER);
>       rootElem->appendChild(msgElem);
> 
>       msgElem->setAttribute( WSZ_PRODUCTVERSION, 
>((CWinAppEx*)AfxGetApp())->GetApplicationProductVersion() );
> 
>       DOMNode* rootElem = m_pDomDocument->getDocumentElement();
> 
>       DOMElement*  typeElem = m_pDomDocument->createElement(WSZ_TYPE);
>       rootElem->appendChild(typeElem);
> 
>       DOMText*    typeVal = m_pDomDocument->createTextNode( WSZ_MSG_POWERUP );
>       typeElem->appendChild(typeVal);
> }
> 
> //Here is the code that converts the DOM document to a stream...
> bool IMessage::CreateSeralizedXMLMemoryBuffer()
> {
>       DOMWriter* pDOMWriter = NULL;
>       XMLFormatTarget* pXMLFormatTarget = NULL;
> 
>       try
>       {
>               // get a serializer, an instance of DOMWriter
>               // Note: LS stands for Load & Save.
>               DOMImplementation* pDOMImplementation = 
>DOMImplementationRegistry::getDOMImplementation(L"LS");
>               if (!pDOMImplementation) return false;
> 
>               pDOMWriter = 
>((DOMImplementationLS*)pDOMImplementation)->createDOMWriter();
>               if (!pDOMWriter) return false;
> 
>               // set user specified end of line sequence and output encoding
>               pDOMWriter->setNewLine(g_MyEOLSequence);
>               pDOMWriter->setEncoding(WSZ_ENCODING_UNICODE_LE);
> 
>               // Plug in a format target to receive the resultant
>               // XML stream from the serializer.      
>               pXMLFormatTarget = new MemBufFormatTarget();
> 
>               //
>               // do the serialization through DOMWriter::writeNode();
>               //
>               if (!pDOMWriter->writeNode(pXMLFormatTarget, (const 
>DOMNode&)*m_pDomDocument))
>               {
>                       delete pXMLFormatTarget;
>                       pXMLFormatTarget = NULL;
>                       delete pDOMWriter;
>                       pDOMWriter = NULL;
> 
>                       return false;
>               }
> 
>               delete pDOMWriter;
> 
>               m_uiBufferLen = ((MemBufFormatTarget*)pXMLFormatTarget)->getLen();
>               
>               m_pxmlbytBuffer = new XMLByte[m_uiBufferLen + 2];
>               memcpy( m_pxmlbytBuffer, 
>(XMLByte*)((MemBufFormatTarget*)pXMLFormatTarget)->getRawBuffer(), m_uiBufferLen );
>               m_pxmlbytBuffer[m_uiBufferLen] = NULL;
>               m_pxmlbytBuffer[m_uiBufferLen+1] = NULL;
> 
>               // For test purposes...it is nice to see this as a character (Unicode) 
>buffer.
>               XMLCh* pxmlchBuffer = (XMLCh*)m_pxmlbytBuffer;
> 
>               delete pXMLFormatTarget;
>               pXMLFormatTarget = NULL;
> 
>               return true;
>       }
>       catch(DOMException e)
>       {
>               if (pDOMWriter)
>               {
>                       delete pDOMWriter;
>                       pDOMWriter = NULL;
>               }
> 
>               if (pXMLFormatTarget)
>               {
>                       delete pXMLFormatTarget;
>                       pXMLFormatTarget = NULL;
>               }
> 
>               return false;
>       }
> }
> 
> // This code takes the stream and makes a DOM Document...
> DOMDocument* IMessage::BuildMsg( XMLByte* szXMLStream, unsigned int uiXMLStreamLen )
> { 
>       // CDOMInputSourceByteStream class defined below...
>       CDOMInputSourceByteStream domInputSource( szXMLStream, uiXMLStreamLen );
> 
>       DOMImplementation* pDOMImplementation = 
>DOMImplementationRegistry::getDOMImplementation(L"LS");
>       if (!pDOMImplementation) return NULL;
>       DOMBuilder* pDOMBuilder = 
>((DOMImplementationLS*)pDOMImplementation)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS,
> 0);
>       if (!pDOMBuilder) return NULL;
> 
>       DOMDocument* pDomDocument = NULL;
>       DOMDocument* pDomDocumentCopy = NULL;
>       try
>       {
>               pDomDocument = pDOMBuilder->parse( domInputSource );
>     
>               pDomDocumentCopy = (DOMDocument*)pDomDocument->cloneNode(true);
> 
>               pDOMBuilder->release();
>       }
>       catch (...)
>       {
>               return NULL;
>       }
>       
>       return pDomDocumentCopy;
> }
> 
> // Globals and classes used above...
> static const XMLCh*             g_MyEOLSequence         = 0;
> static const XMLCh*             g_MemBufId              = L"ATDNewsXMLStreamID";
> 
> class CDOMInputSourceByteStream : public DOMInputSource
> {
> public:
>       CDOMInputSourceByteStream( XMLByte* pxmlbytStream, unsigned int uiStreamLen )
>       {
>               m_pxmlchBaseURI = NULL;
>               m_pxmlchSystemId = NULL;
>               m_pxmlchEncoding = NULL;
>               m_pxmlchPublicId = NULL;
>               m_bIssueFatalErrorIfNotFound = true;
> 
>               m_pxmlbytStream = pxmlbytStream;
>               m_uiStreamLen = uiStreamLen;
>       }
> 
>       virtual BinInputStream* makeStream() const
>       {
>               BinInputStream* pBinInputStream = new BinMemInputStream( 
>m_pxmlbytStream,
>                       m_uiStreamLen,
>                       BinMemInputStream::BufOpt_Reference );
> 
>               return pBinInputStream;
>       }
> 
>       virtual void  setEncoding (const XMLCh *const encodingStr)
>       {
>               m_pxmlchEncoding = (XMLCh*)encodingStr;
>       }
>    
>       virtual void  setPublicId (const XMLCh *const publicId)
>       {
>               m_pxmlchPublicId = (XMLCh*)publicId;
>       }
>    
>       virtual void  setSystemId (const XMLCh *const systemId)
>       {
>               m_pxmlchSystemId = (XMLCh*)systemId;
>       }
>    
>       virtual void  setBaseURI (const XMLCh *const baseURI)
>       {
>               m_pxmlchBaseURI = (XMLCh*)baseURI;
>       }
> 
>       virtual void  setIssueFatalErrorIfNotFound (const bool flag)
>       {
>               m_bIssueFatalErrorIfNotFound = (XMLCh*)flag;
>       }
>    
>       virtual const bool getIssueFatalErrorIfNotFound() const
>       {
>               return m_bIssueFatalErrorIfNotFound;
>       }
>    
>       virtual void  release ()
>       {
>       }
> 
>       virtual const XMLCh* getEncoding() const
>       {
>               return m_pxmlchEncoding;
>       }
> 
>     virtual const XMLCh* getPublicId() const
>       {
>               return m_pxmlchPublicId;
>       }
>  
>     virtual const XMLCh* getSystemId() const
>       {
>               return m_pxmlchSystemId;
>       }
> 
>     virtual const XMLCh* getBaseURI() const
>       {
>               return m_pxmlchBaseURI;
>       }
> 
> private:
>       XMLCh*                  m_pxmlchBaseURI;
>       XMLCh*                  m_pxmlchSystemId;
>       XMLCh*                  m_pxmlchPublicId;
>       XMLCh*                  m_pxmlchEncoding;
>       bool                    m_bIssueFatalErrorIfNotFound;
>       XMLByte*                m_pxmlbytStream;
>       unsigned int    m_uiStreamLen;
> };
> 
> I would expect the Document I started with and the Document I recreate would be the 
>same(equivalent).  My DOMDocument is contained in a IMessage object.  The IMessage 
>class has an operator== like...
> 
> bool IMessage::operator==(const IMessage& rhs ) const
> {     
>       if( m_pDomDocument)
>       {
>               if( !rhs.m_pDomDocument)
>                       return false;
> 
>               if (!(m_pDomDocument->isEqualNode((const DOMNode*)rhs.m_pDomDocument)))
>                       return false;
>       }
>       else if( rhs.m_pDomDocument)
>               return false;
> }
> 
> The ...isEqualNode fails when it gets to checking the localName.  It is null in one 
>object and set to a string (I forget the value) in the other.
> 
> Any help would be greatly appreciated.
> 
> -dh
> 
> -----Original Message-----
> From: Gareth Reakes [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, October 01, 2002 4:01 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Serialize and unserialize DOMDocument over socket
> 
> 
> Hi,
>       post your code and Ill take a look.
> 
> 
> Gareth
> 
> 
> On Mon, 30 Sep 2002, David Hoffer wrote:
> 
> > I am trying to create rather simple DOM documents and send them over
> > sockets, I then repackage the socket stream, on the receiving end, into DOM
> > documents.
> > 
> > I would expect the documents to be the same, i.e. isEqualNode would return
> > true.  However, it is failing at least because the LocalName is not the
> > same.
> > 
> > Can someone help me with this?  Why does the localName not match?  I
> > understand this might be a level 1 vs. 2 issue but what do I do about that?
> > Is there some code where others have did something similar?
> > 
> > -dh
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> > 
> 
> 

-- 
Gareth Reakes, Head of Product Development  
DecisionSoft Ltd.            http://www.decisionsoft.com
Office: +44 (0) 1865 203192



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to