Hi,
createDocument is a xerces non standard extension.
hope this clears it up
Gareth
On Wed, 2 Oct 2002, Bagepalli, Kiran wrote:
> Excuse my ignorance. Is the createDocument() method deprecated.
> I used to write code as DOMDocument* pDOMDocument =
> m_pImpl->createDocument();
> DOMElement* pRootElement =
> pDOMDocument->createElementNS("www.abc.com", "a:rootNode");
> pDOMDocument->insertBefore(pRootElement);
>
> Is this replaced with m_pImpl->createDocument("www.abc.com", "a:rootNode",
> null) in DOM2.
>
> I am a little confused on the namespace for the DOMDocument and the
> namespace for the root element. Are they the same.
> Can someone through light on this please.
> Thanks
> Kiran
>
>
> -----Original Message-----
> From: Gareth Reakes [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, October 02, 2002 9:26 AM
> To: [EMAIL PROTECTED]
> Subject: RE: Serialize and unserialize DOMDocument over socket
>
>
> Hi,
> If you just pass in 0 for the uri bit of the create methods tehn
> it should all work. It does for me.
>
>
> Gareth
>
>
>
> On Wed, 2 Oct 2002, Dave Hoffer wrote:
>
> > Hi,
> >
> > I sort of understand what you are saying.
> >
> > For my application, I do not think I need namespaces. I only added them
> to solve the localName problem. Yes, WSZ_NAMESPACE_URI is not null because,
> again I thought I had to add this to solve the localName problem.
> >
> > All I am trying to do is take some rather simple XML documents, serialize
> them, send them over a socket, recreate the XML document on the other side.
> I am using isNodeEqual() in my UnitTests just to validate that I can do the
> above steps. I rather hate to go to some level 3 not quite implemented
> techniques to do this, but I will if I have to.
> >
> > What do you suggest to do what I am trying to do? It seems to me with all
> the XML-RPC stuff, I have heard of, this should have been done by lots of
> people at this point. By-the-way, I would love to see some code or
> libraries that do the above steps, if it exists.
> >
> > Thanks for your help.
> >
> > -dh
> >
> > -----Original Message-----
> > From: Gareth Reakes [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, October 02, 2002 11:50 AM
> > To: [EMAIL PROTECTED]
> > Subject: RE: Serialize and unserialize DOMDocument over socket
> >
> >
> > Hi,
> > I completely forgot about this problem as I replaced your ns info
> > with nulls. Sorry about that. I assume that WSZ_NAMESPACE_URI is not null.
>
> > If this is the case then when you serialize it you will lose the namespace
>
> > information. When you parse it again the elements will have a different ns
>
> > (ie null). There is a level 3 method that "namespace normalizes" the
> > document and puts in prefix bindings where required. If you applied this
> > to your document prior to serialization then it should be OK.
> > Unfortunately this method has not yet been implemented in xerces-c. It was
>
> > on my todo list for this week but when I went and looked at the method
> > again the scope had vastly increased. I have some quite horrible code that
>
> > does this (but not to the new standard) and you are quite welcome to have
> > that if you want.
> >
> > Gareth
> >
> >
> >
> > On Wed, 2 Oct 2002, Dave Hoffer wrote:
> >
> > > Hi Gareth,
> > >
> > > Right you are. I have fixed this...the new code is below. However, I
> have the same problem, the namespaceURI's do not match (one is null).
> > >
> > > bool IMessage::FillMsg()
> > > {
> > > DOMImplementation* impl =
> DOMImplementationRegistry::getDOMImplementation(L"Core");
> > >
> > > m_pDomDocument = impl->createDocument(
> > > WSZ_NAMESPACE_URI, // 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->createElementNS(WSZ_NAMESPACE_URI,
> > > WSZ_HEADER);
> > >
> > > rootElem->appendChild(msgElem);
> > >
> > > msgElem->setAttributeNS( WSZ_NAMESPACE_URI,
> > > WSZ_PRODUCTVERSION,
> > > ((CWinAppEx*)AfxGetApp())->GetApplicationProductVersion() );
> > >
> > > DOMElement* typeElem = m_pDomDocument->createElementNS(
> WSZ_NAMESPACE_URI, WSZ_TYPE);
> > > rootElem->appendChild(typeElem);
> > >
> > > DOMText* typeVal = m_pDomDocument->createTextNode(
> WSZ_MSG_POWERUP );
> > > typeElem->appendChild(typeVal);
> > >
> > > return true;
> > > }
> > >
> > > -----Original Message-----
> > > From: Gareth Reakes [mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, October 02, 2002 11:12 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: RE: Serialize and unserialize DOMDocument over socket
> > >
> > >
> > > Hi,
> > > comment below
> > >
> > >
> > > On Wed, 2 Oct 2002, Dave Hoffer wrote:
> > >
> > > > Here is the code...
> > > >
> > > > bool IMessage::FillMsg()
> > > > {
> > > > DOMImplementation* impl =
> DOMImplementationRegistry::getDOMImplementation(L"Core");
> > > >
> > > > m_pDomDocument = impl->createDocument(
> > > > WSZ_NAMESPACE_URI, // 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->createElementNS(
> WSZ_NAMESPACE_URI, WSZ_HEADER );
> > > > rootElem->appendChild( msgElem );
> > > >
> > > > msgElem->setAttribute( WSZ_PRODUCTVERSION,
> ((CWinAppEx*)AfxGetApp())->GetApplicationProductVersion() );
> > >
> > > should be setAttributeNS
> > >
> > >
> > >
> > > Gareth
> > >
> > >
> > > >
> > > > DOMNode* rootElem = m_pDomDocument->getDocumentElement();
> > > >
> > > > DOMElement* typeElem = m_pDomDocument->createElementNS(
> WSZ_NAMESPACE_URI, WSZ_TYPE );
> > > > rootElem->appendChild(typeElem);
> > > >
> > > > DOMText* typeVal = m_pDomDocument->createTextNode(
> WSZ_MSG_POWERUP );
> > > > typeElem->appendChild(typeVal);
> > > >
> > > > return true;
> > > > }
> > > >
> > > > -dh
> > > >
> > > >
> > > >
> > > > -----Original Message-----
> > > > From: Gareth Reakes [mailto:[EMAIL PROTECTED]]
> > > > Sent: Wednesday, October 02, 2002 11:04 AM
> > > > To: [EMAIL PROTECTED]
> > > > Subject: RE: Serialize and unserialize DOMDocument over socket
> > > >
> > > >
> > > > Hi,
> > > > post you document creation stuff (the stuff in FillDoc) and Ill
> > > > have a look.
> > > >
> > > > Gareth
> > > >
> > > >
> > > >
> > > > On Wed, 2 Oct 2002, Dave Hoffer wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > Thank you for the replies. I did what you said, this HAS FIXED the
> localName issue. Thank you very much. However, the very next test in the
> isEqualNode code is a check of getNamespaceURI()'s. This fails.
> > > > >
> > > > > What seems to be happening is that the object that we create from
> the byte stream seems to have the valid NamespaceURI but the orginial object
> does not. What would be causing this?
> > > > >
> > > > > Again thanks for your help!
> > > > >
> > > > > -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(DOMImplementati
> onLS::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]