From 3c8d482efbdc7882ba4db5d7a61cb3c81ffb6f95 Mon Sep 17 00:00:00 2001
From: Andy Heninger <andyh@apache.org>
Date: Sat, 3 Jun 2000 00:29:06 +0000
Subject: [PATCH] COM Wrapper changes from Curt Arnold

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@172147 13f79535-47bb-0310-9956-ffa450edef68
---
 src/com/IXMLDOMNodeImpl.h             |  18 +
 src/com/IXMLDOMNodeImpl.inl           |  49 ++-
 src/com/StdAfx.cpp                    |  14 +
 src/com/StdAfx.h                      |  27 ++
 src/com/XMLDOMAttribute.h             |   5 +-
 src/com/XMLDOMCDATASection.h          |   5 +-
 src/com/XMLDOMComment.h               |   5 +-
 src/com/XMLDOMDocument.cpp            |  34 +-
 src/com/XMLDOMDocument.h              |   9 +-
 src/com/XMLDOMDocumentFragment.h      |   5 +-
 src/com/XMLDOMDocumentType.h          |   5 +-
 src/com/XMLDOMElement.h               |   5 +-
 src/com/XMLDOMEntity.h                |   5 +-
 src/com/XMLDOMEntityReference.h       |   5 +-
 src/com/XMLDOMImplementation.h        |   5 +-
 src/com/XMLDOMNamedNodeMap.h          |   5 +-
 src/com/XMLDOMNodeList.h              |   5 +-
 src/com/XMLDOMNotation.h              |   5 +-
 src/com/XMLDOMParseError.h            |   5 +-
 src/com/XMLDOMProcessingInstruction.h |   5 +-
 src/com/XMLDOMText.h                  |   5 +-
 src/com/XMLDOMUtil.cpp                | 540 +++++++++++++++++++++++---
 src/com/XMLDOMUtil.h                  |   5 +
 src/com/XMLHTTPRequest.cpp            |  14 +-
 src/com/XMLHttpRequest.h              |   7 +-
 src/com/xml4com.cpp                   |  28 +-
 src/com/xml4com.idl                   |  71 +++-
 src/com/xml4com.rc                    |  73 +++-
 28 files changed, 848 insertions(+), 116 deletions(-)

diff --git a/src/com/IXMLDOMNodeImpl.h b/src/com/IXMLDOMNodeImpl.h
index e01b74d73..b3daab2ac 100644
--- a/src/com/IXMLDOMNodeImpl.h
+++ b/src/com/IXMLDOMNodeImpl.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:54  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:12  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -64,6 +67,21 @@
 #ifndef ___ixmldomnodeimpl_h___
 #define ___ixmldomnodeimpl_h___
 
+
+//
+//   This macro is defined in MSXML.H's compatible with IE5
+//      and not defined in those from IE4.
+//
+//   To correct, install a IE5 or later version of the Microsoft Platform SDK
+//      and add \Program Files\Microsoft Platform SDK\Include as the first entry
+//      on the Directories tab on the dialog displayed after selecting Tools Options
+//      from the Visual Studio IDE.
+//
+#ifndef __IXMLDOMNode_INTERFACE_DEFINED__
+#error "xerces-dom requires an MSXML.H compatible with IE5 or later.  See comments for directions to correct this problem."
+#endif
+
+
 template <class T, const IID* piid, const GUID* plibid = &CComModule::m_libid, WORD wMajor = 1,
 WORD wMinor = 0, class tihclass = CComTypeInfoHolder>
 class ATL_NO_VTABLE IXMLDOMNodeImpl: 
diff --git a/src/com/IXMLDOMNodeImpl.inl b/src/com/IXMLDOMNodeImpl.inl
index 2688ccf1f..120c30903 100644
--- a/src/com/IXMLDOMNodeImpl.inl
+++ b/src/com/IXMLDOMNodeImpl.inl
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:54  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:12  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -63,6 +66,7 @@
 
 
 #include <dom/DOM_Node.hpp>
+#include <dom/DOM_Document.hpp>
 #include "XMLDOMNodeList.h"
 #include "XMLDOMNamedNodeMap.h"
 #include "XMLDOMUtil.h"
@@ -221,12 +225,19 @@ IXMLDOMNodeImpl<T,piid,plibid,wMajor,wMinor,tihclass>::get_firstChild(IXMLDOMNod
 	if (NULL == pVal)
 		return E_POINTER;
 
+	if(*pVal) (*pVal)->Release();
 	*pVal = NULL;
+
 	HRESULT hr = S_OK;
 
 	try
 	{
-		hr = wrapNode(m_pIXMLDOMDocument,get_DOM_Node().getFirstChild(),IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal));
+		DOM_Node n = get_DOM_Node().getFirstChild();
+		//
+		//   returns Nothing if no children
+		//
+		if(!n.isNull())
+			hr = wrapNode(m_pIXMLDOMDocument,n,IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal));
 	}
 	catch(...)
 	{
@@ -246,12 +257,16 @@ IXMLDOMNodeImpl<T,piid,plibid,wMajor,wMinor,tihclass>::get_lastChild(IXMLDOMNode
 	if (NULL == pVal)
 		return E_POINTER;
 
+	if(*pVal) (*pVal)->Release();
 	*pVal = NULL;
+
 	HRESULT hr = S_OK;
 
 	try
 	{
-		hr = wrapNode(m_pIXMLDOMDocument,get_DOM_Node().getLastChild(),IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal));
+		DOM_Node n = get_DOM_Node().getLastChild();
+		if(!n.isNull())
+			hr = wrapNode(m_pIXMLDOMDocument,n,IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal));
 	}
 	catch(...)
 	{
@@ -271,12 +286,15 @@ IXMLDOMNodeImpl<T,piid,plibid,wMajor,wMinor,tihclass>::get_previousSibling(IXMLD
 	if (NULL == pVal)
 		return E_POINTER;
 
+	if(*pVal) (*pVal)->Release();
 	*pVal = NULL;
 	HRESULT hr = S_OK;
 
 	try
 	{
-		hr = wrapNode(m_pIXMLDOMDocument,get_DOM_Node().getPreviousSibling(),IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal));
+		DOM_Node n = get_DOM_Node().getPreviousSibling();
+		if(!n.isNull())
+			hr = wrapNode(m_pIXMLDOMDocument,n,IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal));
 	}
 	catch(...)
 	{
@@ -296,12 +314,16 @@ IXMLDOMNodeImpl<T,piid,plibid,wMajor,wMinor,tihclass>::get_nextSibling(IXMLDOMNo
 	if (NULL == pVal)
 		return E_POINTER;
 
+	if(*pVal) (*pVal)->Release();
 	*pVal = NULL;
+
 	HRESULT hr = S_OK;
 
 	try
 	{
-		hr = wrapNode(m_pIXMLDOMDocument,get_DOM_Node().getNextSibling(),IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal));
+		DOM_Node n = get_DOM_Node().getNextSibling();
+		if(!n.isNull())
+			hr = wrapNode(m_pIXMLDOMDocument,n,IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal));
 	}
 	catch(...)
 	{
@@ -666,7 +688,24 @@ IXMLDOMNodeImpl<T,piid,plibid,wMajor,wMinor,tihclass>::put_text(BSTR newVal)
 
 	try
 	{
-		get_DOM_Node().setNodeValue(newVal);
+		if(NODE_ELEMENT == type)
+		{
+			//
+			//   remove all child elements
+			//
+			DOM_Node elem = get_DOM_Node();
+			DOM_Node child = elem.getLastChild();
+			while(!child.isNull())
+			{
+				elem.removeChild(child);
+				child = elem.getLastChild();
+			}
+			
+			DOM_Document doc = elem.getOwnerDocument();
+			elem.appendChild(doc.createTextNode(newVal));
+		}
+		else
+			get_DOM_Node().setNodeValue(newVal);
 	}
 	catch(...)
 	{
diff --git a/src/com/StdAfx.cpp b/src/com/StdAfx.cpp
index a5eea178f..093a22d41 100644
--- a/src/com/StdAfx.cpp
+++ b/src/com/StdAfx.cpp
@@ -10,3 +10,17 @@
 #endif
 
 #include <atlimpl.cpp>
+
+//
+//   This macro is defined in MSXML.H's compatible with IE5
+//      and not defined in those from IE4.
+//
+//   To correct, install a IE5 or later version of the Microsoft Platform SDK
+//      and add \Program Files\Microsoft Platform SDK\Include as the first entry
+//      on the Directories tab on the dialog displayed after selecting Tools Options
+//      from the Visual Studio IDE.
+//
+#ifndef __IXMLDOMNode_INTERFACE_DEFINED__
+#error "xerces-dom requires an MSXML.H compatible with IE5 or later.  See comments for directions to correct this problem."
+#endif
+
diff --git a/src/com/StdAfx.h b/src/com/StdAfx.h
index abbda54eb..a1c40fb9e 100644
--- a/src/com/StdAfx.h
+++ b/src/com/StdAfx.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:55  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:12  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -78,6 +81,16 @@
 #endif
 #define _ATL_APARTMENT_THREADED
 
+#define DOMDocument _MSXMLDOMDocument
+#define XMLHTTPRequest _MSXMLHTTPRequest
+#define CLSID_DOMDocument CLSID_MSDOMDocument
+#define CLSID_XMLHTTPRequest CLSID_MSXMLHTTPRequest
+
+//
+//   suppress MSXML.H since we duplicate some of the information
+//      in xml4com.h
+//
+
 #include <atlbase.h>
 //You may derive a class from CComModule and use it if you want to override
 //something, but do not change the name of _Module
@@ -91,8 +104,22 @@ extern CComModule _Module;
 #include <process.h>
 #include <Wininet.h>
 
+#undef DOMDocument
+#undef XMLHTTPRequest
+#undef CLSID_DOMDocument
+#undef CLSID_XMLHTTPRequest
+
+//
+//   These are defined in xml4dom_i.c which is included in xml4dom.cpp
+//
+//
+extern const IID CLSID_DOMDocument;
+extern const IID CLSID_XMLHTTPRequest;
+extern const IID LIBID_Xerces;
+
 const long	MSG_READY_STATE_CHANGE = WM_APP + 0x0001;
 
+
 //{{AFX_INSERT_LOCATION}}
 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 
diff --git a/src/com/XMLDOMAttribute.h b/src/com/XMLDOMAttribute.h
index 6321061ef..6ef509be4 100644
--- a/src/com/XMLDOMAttribute.h
+++ b/src/com/XMLDOMAttribute.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:55  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:12  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMAttribute : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMNodeImpl<IXMLDOMAttribute, &IID_IXMLDOMAttribute, &LIBID_IBMXMLLib>
+	public IXMLDOMNodeImpl<IXMLDOMAttribute, &IID_IXMLDOMAttribute, &LIBID_Xerces>
 {
 public:
 	CXMLDOMAttribute()
diff --git a/src/com/XMLDOMCDATASection.h b/src/com/XMLDOMCDATASection.h
index 6e0d25797..bae438511 100644
--- a/src/com/XMLDOMCDATASection.h
+++ b/src/com/XMLDOMCDATASection.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:55  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:11  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMCDATASection : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMTextImpl<IXMLDOMCDATASection, &IID_IXMLDOMCDATASection, &LIBID_IBMXMLLib>
+	public IXMLDOMTextImpl<IXMLDOMCDATASection, &IID_IXMLDOMCDATASection, &LIBID_Xerces>
 {
 public:
 	CXMLDOMCDATASection()
diff --git a/src/com/XMLDOMComment.h b/src/com/XMLDOMComment.h
index 2473a2f8a..a9d964ad8 100644
--- a/src/com/XMLDOMComment.h
+++ b/src/com/XMLDOMComment.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:57  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:11  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMComment : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMCharacterDataImpl<IXMLDOMComment, &IID_IXMLDOMComment, &LIBID_IBMXMLLib>
+	public IXMLDOMCharacterDataImpl<IXMLDOMComment, &IID_IXMLDOMComment, &LIBID_Xerces>
 {
 public:
 	CXMLDOMComment()
diff --git a/src/com/XMLDOMDocument.cpp b/src/com/XMLDOMDocument.cpp
index f73478074..1e6cad71f 100644
--- a/src/com/XMLDOMDocument.cpp
+++ b/src/com/XMLDOMDocument.cpp
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:57  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:11  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -83,6 +86,7 @@
 #include "XMLDOMAttribute.h"
 #include "XMLDOMEntityReference.h"
 #include "BindStatusCallback.h"
+#include <dom/DocumentImpl.hpp>
 
 // I need to make sure the file is registered with long filenames
 HRESULT WINAPI CXMLDOMDocument::UpdateRegistry(BOOL bRegister)
@@ -144,6 +148,9 @@ HRESULT CXMLDOMDocument::FinalConstruct()
 	
 	m_pParseError->AddRef();
 	m_pIXMLDOMDocument = this;
+
+	m_Document = DOM_Document::createDocument();
+
 	return hr;
 }
 
@@ -183,7 +190,14 @@ void CXMLDOMDocument::warning(const SAXParseException& exception)
 
 void CXMLDOMDocument::error(const SAXParseException& exception)
 {
-	// ignore errors
+	m_pParseError->SetData(1,
+						   exception.getSystemId(),
+						   exception.getMessage(),
+						   _T(""),
+						   exception.getLineNumber(),
+						   exception.getColumnNumber(),
+						   0);
+	m_bParseError = true;
 }
 
 void CXMLDOMDocument::fatalError(const SAXParseException& exception)
@@ -233,15 +247,8 @@ LRESULT CXMLDOMDocument::OnReadyStateChange(UINT uMsg, WPARAM wParam, LPARAM lPa
 
 STDMETHODIMP CXMLDOMDocument::InterfaceSupportsErrorInfo(REFIID riid)
 {
-	static const IID* arr[] = 
-	{
-		&IID_IXMLDOMDocument
-	};
-	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
-	{
-		if (InlineIsEqualGUID(*arr[i],riid))
-			return S_OK;
-	}
+	if (IsEqualGUID(IID_IXMLDOMDocument,riid))
+		return S_OK;
 	return S_FALSE;
 }
 
@@ -348,7 +355,7 @@ STDMETHODIMP CXMLDOMDocument::putref_documentElement(IXMLDOMElement  *newVal)
 	try
 	{
 		elem = m_Document.getDocumentElement();
-		if (NULL == newVal) {
+		if (NULL == newVal && !elem.isNull()) {
 			m_Document.removeChild(elem);
 			return S_OK;
 		}
@@ -373,7 +380,10 @@ STDMETHODIMP CXMLDOMDocument::putref_documentElement(IXMLDOMElement  *newVal)
 
 	try
 	{
-		m_Document.replaceChild(*pNewValNode, elem);
+		if(elem.isNull())
+			m_Document.appendChild(*pNewValNode);
+		else
+			m_Document.replaceChild(*pNewValNode, elem);
 	}
 	catch(...)
 	{
diff --git a/src/com/XMLDOMDocument.h b/src/com/XMLDOMDocument.h
index 53e28ca33..e8d596deb 100644
--- a/src/com/XMLDOMDocument.h
+++ b/src/com/XMLDOMDocument.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:57  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:11  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -77,14 +80,14 @@ class SAXParseException;
 
 class ATL_NO_VTABLE CXMLDOMDocument : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public CComCoClass<CXMLDOMDocument, &CLSID_XMLDOMDocument>,
+	public CComCoClass<CXMLDOMDocument, &CLSID_DOMDocument>,
 	public IObjectSafetyImpl<CXMLDOMDocument, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
-	public IXMLDOMNodeImpl<IXMLDOMDocument, &IID_IXMLDOMDocument, &LIBID_IBMXMLLib>,
+	public IXMLDOMNodeImpl<IXMLDOMDocument, &IID_IXMLDOMDocument, &LIBID_Xerces>,
 	public IObjectWithSiteImpl<CXMLDOMDocument>,
 	public ISupportErrorInfo,
 	public CProxyXMLDOMDocumentEvents< CXMLDOMDocument >,
 	public IConnectionPointContainerImpl<CXMLDOMDocument>,
-	public IProvideClassInfo2Impl<&CLSID_XMLDOMDocument, &DIID_XMLDOMDocumentEvents, &LIBID_IBMXMLLib>,
+	public IProvideClassInfo2Impl<&CLSID_DOMDocument, &DIID_XMLDOMDocumentEvents, &LIBID_Xerces>,
 	public CWindowImpl<CXMLDOMDocument, CWindow, CWinTraits<0,0> >,
 	ErrorHandler
 {
diff --git a/src/com/XMLDOMDocumentFragment.h b/src/com/XMLDOMDocumentFragment.h
index 2794c8015..e562f49b6 100644
--- a/src/com/XMLDOMDocumentFragment.h
+++ b/src/com/XMLDOMDocumentFragment.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:58  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:11  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMDocumentFragment : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMNodeImpl<IXMLDOMDocumentFragment, &IID_IXMLDOMDocumentFragment, &LIBID_IBMXMLLib>
+	public IXMLDOMNodeImpl<IXMLDOMDocumentFragment, &IID_IXMLDOMDocumentFragment, &LIBID_Xerces>
 {
 public:
 	CXMLDOMDocumentFragment()
diff --git a/src/com/XMLDOMDocumentType.h b/src/com/XMLDOMDocumentType.h
index 8f875f4b5..06239a827 100644
--- a/src/com/XMLDOMDocumentType.h
+++ b/src/com/XMLDOMDocumentType.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:58  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:11  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMDocumentType : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMNodeImpl<IXMLDOMDocumentType, &IID_IXMLDOMDocumentType, &LIBID_IBMXMLLib>
+	public IXMLDOMNodeImpl<IXMLDOMDocumentType, &IID_IXMLDOMDocumentType, &LIBID_Xerces>
 {
 public:
 	CXMLDOMDocumentType()
diff --git a/src/com/XMLDOMElement.h b/src/com/XMLDOMElement.h
index 3a6e8c7e6..e12026a3a 100644
--- a/src/com/XMLDOMElement.h
+++ b/src/com/XMLDOMElement.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:59  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:11  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMElement : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMNodeImpl<IXMLDOMElement, &IID_IXMLDOMElement, &LIBID_IBMXMLLib>
+	public IXMLDOMNodeImpl<IXMLDOMElement, &IID_IXMLDOMElement, &LIBID_Xerces>
 {
 public:
 	CXMLDOMElement()
diff --git a/src/com/XMLDOMEntity.h b/src/com/XMLDOMEntity.h
index 272a1c8e8..bca138129 100644
--- a/src/com/XMLDOMEntity.h
+++ b/src/com/XMLDOMEntity.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:59  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:11  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMEntity : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMNodeImpl<IXMLDOMEntity, &IID_IXMLDOMEntity, &LIBID_IBMXMLLib>
+	public IXMLDOMNodeImpl<IXMLDOMEntity, &IID_IXMLDOMEntity, &LIBID_Xerces>
 {
 public:
 	CXMLDOMEntity()
diff --git a/src/com/XMLDOMEntityReference.h b/src/com/XMLDOMEntityReference.h
index 92c739709..d8075a643 100644
--- a/src/com/XMLDOMEntityReference.h
+++ b/src/com/XMLDOMEntityReference.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:59  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:10  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMEntityReference : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMNodeImpl<IXMLDOMEntityReference, &IID_IXMLDOMEntityReference, &LIBID_IBMXMLLib>
+	public IXMLDOMNodeImpl<IXMLDOMEntityReference, &IID_IXMLDOMEntityReference, &LIBID_Xerces>
 {
 public:
 	CXMLDOMEntityReference()
diff --git a/src/com/XMLDOMImplementation.h b/src/com/XMLDOMImplementation.h
index a81c165db..0892a5dfc 100644
--- a/src/com/XMLDOMImplementation.h
+++ b/src/com/XMLDOMImplementation.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:28:59  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:10  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -68,7 +71,7 @@
 
 class ATL_NO_VTABLE CXMLDOMImplementation : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IDispatchImpl<IXMLDOMImplementation, &IID_IXMLDOMImplementation, &LIBID_IBMXMLLib>
+	public IDispatchImpl<IXMLDOMImplementation, &IID_IXMLDOMImplementation, &LIBID_Xerces>
 {
 public:
 	CXMLDOMImplementation()
diff --git a/src/com/XMLDOMNamedNodeMap.h b/src/com/XMLDOMNamedNodeMap.h
index 9d889f04a..7b262e666 100644
--- a/src/com/XMLDOMNamedNodeMap.h
+++ b/src/com/XMLDOMNamedNodeMap.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:00  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:10  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMNamedNodeMap : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IDispatchImpl<IXMLDOMNamedNodeMap, &IID_IXMLDOMNamedNodeMap, &LIBID_IBMXMLLib>,
+	public IDispatchImpl<IXMLDOMNamedNodeMap, &IID_IXMLDOMNamedNodeMap, &LIBID_Xerces>,
 	public NodeContainerImpl<DOM_NamedNodeMap>
 {
 public:
diff --git a/src/com/XMLDOMNodeList.h b/src/com/XMLDOMNodeList.h
index 067f96ed7..7a566c263 100644
--- a/src/com/XMLDOMNodeList.h
+++ b/src/com/XMLDOMNodeList.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:00  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:10  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMNodeList : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IDispatchImpl<IXMLDOMNodeList, &IID_IXMLDOMNodeList, &LIBID_IBMXMLLib>,
+	public IDispatchImpl<IXMLDOMNodeList, &IID_IXMLDOMNodeList, &LIBID_Xerces>,
 	public NodeContainerImpl<DOM_NodeList>
 {
 public:
diff --git a/src/com/XMLDOMNotation.h b/src/com/XMLDOMNotation.h
index 729ca2d83..4dad779e0 100644
--- a/src/com/XMLDOMNotation.h
+++ b/src/com/XMLDOMNotation.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:00  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:10  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMNotation : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMNodeImpl<IXMLDOMNotation, &IID_IXMLDOMNotation, &LIBID_IBMXMLLib>
+	public IXMLDOMNodeImpl<IXMLDOMNotation, &IID_IXMLDOMNotation, &LIBID_Xerces>
 {
 public:
 	CXMLDOMNotation()
diff --git a/src/com/XMLDOMParseError.h b/src/com/XMLDOMParseError.h
index e060438d7..c3269576c 100644
--- a/src/com/XMLDOMParseError.h
+++ b/src/com/XMLDOMParseError.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:01  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:10  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -66,7 +69,7 @@
 
 class ATL_NO_VTABLE CXMLDOMParseError : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IDispatchImpl<IXMLDOMParseError, &IID_IXMLDOMParseError, &LIBID_IBMXMLLib>
+	public IDispatchImpl<IXMLDOMParseError, &IID_IXMLDOMParseError, &LIBID_Xerces>
 {
 public:
 	CXMLDOMParseError()
diff --git a/src/com/XMLDOMProcessingInstruction.h b/src/com/XMLDOMProcessingInstruction.h
index 10e51654d..46c1d1617 100644
--- a/src/com/XMLDOMProcessingInstruction.h
+++ b/src/com/XMLDOMProcessingInstruction.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:01  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:09  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMProcessingInstruction : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMNodeImpl<IXMLDOMProcessingInstruction, &IID_IXMLDOMProcessingInstruction, &LIBID_IBMXMLLib>
+	public IXMLDOMNodeImpl<IXMLDOMProcessingInstruction, &IID_IXMLDOMProcessingInstruction, &LIBID_Xerces>
 {
 public:
 	CXMLDOMProcessingInstruction()
diff --git a/src/com/XMLDOMText.h b/src/com/XMLDOMText.h
index 12d8e7e48..c3854dbc6 100644
--- a/src/com/XMLDOMText.h
+++ b/src/com/XMLDOMText.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:01  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:09  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -69,7 +72,7 @@
 
 class ATL_NO_VTABLE CXMLDOMText : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public IXMLDOMTextImpl<IXMLDOMText, &IID_IXMLDOMText, &LIBID_IBMXMLLib>
+	public IXMLDOMTextImpl<IXMLDOMText, &IID_IXMLDOMText, &LIBID_Xerces>
 {
 public:
 	CXMLDOMText()
diff --git a/src/com/XMLDOMUtil.cpp b/src/com/XMLDOMUtil.cpp
index 1dd788c3e..aa2478379 100644
--- a/src/com/XMLDOMUtil.cpp
+++ b/src/com/XMLDOMUtil.cpp
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:02  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:09  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -76,6 +79,8 @@
 #include "XMLDOMDocumentFragment.h"
 #include "XMLDOMNotation.h"
 #include "XMLDOMUtil.h"
+#include <util/PlatformUtils.hpp>
+
 
 const TCHAR* g_DomNodeName[] = 
 {	
@@ -122,6 +127,190 @@ void GetText(const DOM_Node& node, _bstr_t &text)
 		text += node.getNodeValue().rawBuffer();
 }
 
+
+
+template <class Base>
+class CComObjectPool
+{
+public:
+	CComObjectPool(unsigned long poolSize);
+
+	virtual ~CComObjectPool();
+
+	HRESULT WINAPI CreateInstance(Base** pp);
+
+	HRESULT Deactivate(Base* obj);
+
+private:
+	Base** m_pool;
+	unsigned long m_size;
+	unsigned long m_hit;
+	unsigned long m_attempt;
+	HRESULT Activate(Base* obj);
+};
+
+
+
+
+template <class Base>
+class CPooledComObject : public Base
+{
+public:
+	typedef Base _BaseClass;
+	CPooledComObject(void* = NULL)
+	{
+		_Module.Lock();
+	}
+	// Set refcount to 1 to protect destruction
+	~CPooledComObject()
+	{
+		m_dwRef = 1L;
+		FinalRelease();
+#ifdef _ATL_DEBUG_INTERFACES
+		_Module.DeleteNonAddRefThunk(_GetRawUnknown());
+#endif
+		_Module.Unlock();
+	}
+	//If InternalAddRef or InternalRelease is undefined then your class
+	//doesn't derive from CComObjectRoot
+	STDMETHOD_(ULONG, AddRef)() {return InternalAddRef();}
+	STDMETHOD_(ULONG, Release)()
+	{
+		ULONG l = InternalRelease();
+		if (l == 0) {
+			if(SUCCEEDED(m_pool.Deactivate(this))) {
+				FinalRelease();
+			}
+			else
+				delete this;
+		}
+		return l;
+	}
+	//if _InternalQueryInterface is undefined then you forgot BEGIN_COM_MAP
+	STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject)
+	{return _InternalQueryInterface(iid, ppvObject);}
+	template <class Q>
+	HRESULT STDMETHODCALLTYPE QueryInterface(Q** pp)
+	{
+		return QueryInterface(__uuidof(Q), (void**)pp);
+	}
+
+	static HRESULT WINAPI CreateInstance(Base** pp) {
+		return m_pool.CreateInstance(pp);
+	}
+
+private:
+	static CComObjectPool<Base> m_pool;
+};
+
+
+
+
+template <class Base>
+CComObjectPool<Base>::CComObjectPool<Base>(unsigned long poolSize) {
+	m_pool = NULL;
+	m_size = poolSize;
+	m_pool = new Base*[m_size];
+	for(unsigned long i = 0; i < m_size; i++)
+		m_pool[i] = NULL;
+	m_hit= 0;
+	m_attempt = 0;
+}
+
+template <class Base>
+CComObjectPool<Base>::~CComObjectPool<Base>() {
+	for(unsigned long i = 0; i < m_size; i++) {
+		if(m_pool[i]) delete m_pool[i];
+	}
+	delete [] m_pool;
+}
+
+template <class Base>
+HRESULT CComObjectPool<Base>::Deactivate(Base* obj) {
+	for(unsigned long i = 0; i < m_size; i++) {
+		if(m_pool[i] == NULL) {
+			m_pool[i] = obj;
+			return S_OK;
+		}
+	}
+	return E_FAIL;
+}
+
+template <class Base>
+HRESULT CComObjectPool<Base>::Activate(Base* p)
+{
+	p->SetVoid(NULL);
+	p->InternalFinalConstructAddRef();
+	HRESULT hRes = p->FinalConstruct();
+	p->InternalFinalConstructRelease();
+	return hRes;
+}
+
+
+template <class Base>
+HRESULT WINAPI CComObjectPool<Base>::CreateInstance(Base** pp) {
+	ATLASSERT(pp != NULL);
+	HRESULT hRes = E_OUTOFMEMORY;
+	Base* p = NULL;
+
+	m_attempt++;
+
+	for(unsigned long i = 0; i < m_size; i++) {
+		if(m_pool[i]) {
+			p = m_pool[i];
+			m_pool[i] = NULL;
+			hRes = Activate(p);
+			if (SUCCEEDED(hRes)) {
+				m_hit++;
+				break;
+			}
+			else {
+				delete p;
+				p = NULL;
+			}
+		}
+	}
+
+	if(FAILED(hRes)) {
+		ATLTRY(p = new CPooledComObject<Base>())
+		if (p != NULL) {
+			hRes = Activate(p);
+			if (hRes != S_OK) {
+				delete p;
+				p = NULL;
+			}
+		}
+	}
+	*pp = p;
+	return hRes;
+}
+
+
+CComObjectPool<CXMLDOMElement> CPooledComObject<CXMLDOMElement>::m_pool(6);
+typedef CPooledComObject<CXMLDOMElement> CPooledXMLDOMElementObj;
+
+CComObjectPool<CXMLDOMAttribute> CPooledComObject<CXMLDOMAttribute>::m_pool(6);
+typedef CPooledComObject<CXMLDOMAttribute> CPooledXMLDOMAttributeObj;
+
+CComObjectPool<CXMLDOMText> CPooledComObject<CXMLDOMText>::m_pool(6);
+typedef CPooledComObject<CXMLDOMText> CPooledXMLDOMTextObj;
+
+CComObjectPool<CXMLDOMCDATASection> CPooledComObject<CXMLDOMCDATASection>::m_pool(6);
+typedef CPooledComObject<CXMLDOMCDATASection> CPooledXMLDOMCDATASectionObj;
+
+CComObjectPool<CXMLDOMEntityReference> CPooledComObject<CXMLDOMEntityReference>::m_pool(6);
+typedef CPooledComObject<CXMLDOMEntityReference> CPooledXMLDOMEntityReferenceObj;
+
+CComObjectPool<CXMLDOMEntity> CPooledComObject<CXMLDOMEntity>::m_pool(6);
+typedef CPooledComObject<CXMLDOMEntity> CPooledXMLDOMEntityObj;
+
+CComObjectPool<CXMLDOMProcessingInstruction> CPooledComObject<CXMLDOMProcessingInstruction>::m_pool(6);
+typedef CPooledComObject<CXMLDOMProcessingInstruction> CPooledXMLDOMProcessingInstructionObj;
+
+CComObjectPool<CXMLDOMComment> CPooledComObject<CXMLDOMComment>::m_pool(6);
+typedef CPooledComObject<CXMLDOMComment> CPooledXMLDOMCommentObj;
+
+
 HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal)
 {
 	HRESULT hr = S_OK;
@@ -140,8 +329,8 @@ HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal
 	{
 	case DOM_Node::ELEMENT_NODE:
 	{
-		CXMLDOMElementObj *pObj = NULL;
-		hr = CXMLDOMElementObj::CreateInstance(&pObj);
+		CXMLDOMElement *pObj = NULL;
+		hr = CPooledXMLDOMElementObj::CreateInstance(&pObj);
 		if (S_OK != hr) 
 			return hr;
 	
@@ -167,8 +356,8 @@ HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal
 	}
 	case DOM_Node::ATTRIBUTE_NODE:
 	{
-		CXMLDOMAttributeObj *pObj = NULL;
-		hr = CXMLDOMAttributeObj::CreateInstance(&pObj);
+		CXMLDOMAttribute *pObj = NULL;
+		hr = CPooledXMLDOMAttributeObj::CreateInstance(&pObj);
 		if (S_OK != hr) 
 			return hr;
 	
@@ -194,8 +383,8 @@ HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal
 	}
 	case DOM_Node::TEXT_NODE:
 	{
-		CXMLDOMTextObj *pObj = NULL;
-		hr = CXMLDOMTextObj::CreateInstance(&pObj);
+		CXMLDOMText *pObj = NULL;
+		hr = CPooledXMLDOMTextObj::CreateInstance(&pObj);
 		if (S_OK != hr) 
 			return hr;
 	
@@ -221,8 +410,8 @@ HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal
 	}
 	case DOM_Node::CDATA_SECTION_NODE:
 	{
-		CXMLDOMCDATASectionObj *pObj = NULL;
-		hr = CXMLDOMCDATASectionObj::CreateInstance(&pObj);
+		CXMLDOMCDATASection *pObj = NULL;
+		hr = CPooledXMLDOMCDATASectionObj::CreateInstance(&pObj);
 		if (S_OK != hr) 
 			return hr;
 	
@@ -248,8 +437,8 @@ HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal
 	}
 	case DOM_Node::ENTITY_REFERENCE_NODE:
 	{
-		CXMLDOMEntityReferenceObj *pObj = NULL;
-		hr = CXMLDOMEntityReferenceObj::CreateInstance(&pObj);
+		CXMLDOMEntityReference *pObj = NULL;
+		hr = CPooledXMLDOMEntityReferenceObj::CreateInstance(&pObj);
 		if (S_OK != hr) 
 			return hr;
 	
@@ -275,8 +464,8 @@ HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal
 	}
 	case DOM_Node::ENTITY_NODE:
 	{
-		CXMLDOMEntityObj *pObj = NULL;
-		hr = CXMLDOMEntityObj::CreateInstance(&pObj);
+		CXMLDOMEntity *pObj = NULL;
+		hr = CPooledXMLDOMEntityObj::CreateInstance(&pObj);
 		if (S_OK != hr) 
 			return hr;
 	
@@ -302,8 +491,8 @@ HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal
 	}
 	case DOM_Node::PROCESSING_INSTRUCTION_NODE:
 	{
-		CXMLDOMProcessingInstructionObj *pObj = NULL;
-		hr = CXMLDOMProcessingInstructionObj::CreateInstance(&pObj);
+		CXMLDOMProcessingInstruction *pObj = NULL;
+		hr = CPooledXMLDOMProcessingInstructionObj::CreateInstance(&pObj);
 		if (S_OK != hr) 
 			return hr;
 	
@@ -329,8 +518,8 @@ HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal
 	}
 	case DOM_Node::COMMENT_NODE:
 	{
-		CXMLDOMCommentObj *pObj = NULL;
-		hr = CXMLDOMCommentObj::CreateInstance(&pObj);
+		CXMLDOMComment *pObj = NULL;
+		hr = CPooledXMLDOMCommentObj::CreateInstance(&pObj);
 		if (S_OK != hr) 
 			return hr;
 	
@@ -470,50 +659,297 @@ HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal
 	return hr;
 }
 
-void GetXML(const DOM_Node &node, _bstr_t &text)
-{
-	DOM_Node::NodeType type = static_cast<DOM_Node::NodeType> (node.getNodeType());
-	
-	if (DOM_Node::TEXT_NODE == type) {
-		_bstr_t value = node.getNodeValue().rawBuffer();
-		if (value.length() > 0) 
-			text += value; 
 
-		return;
+class xmlstream {
+public:
+	xmlstream() {
+		m_length = 0;
+		m_alloc = 0;
+		m_buffer = 0;
+		m_next = 0;
 	}
 
-	_bstr_t tagName = node.getNodeName().rawBuffer();
+	~xmlstream() {
+		delete [] m_buffer;
+	}
 
-	text += _T("<");
-	text += tagName;
+	xmlstream& operator<<(const XMLCh* other) {
+		//
+		//   get length of string
+		//
+		unsigned long len = 0;
+		for(const XMLCh* source = other; *source; source++,len++);
+
+		//
+		//    append to stream
+		//
+		append(other,len);
+		return *this;
+	}
 
-	DOM_NamedNodeMap attrs = node.getAttributes();
+	xmlstream& operator<<(const DOMString& other) {
+		append(other.rawBuffer(),other.length());
+		return *this;
+	}
 
-	int length = 0;
-	if (attrs != 0) {
-		length = attrs.getLength();
-		for (int i=0; i < length; ++i) {
-			DOM_Node attr = attrs.item(i);
-			text += _T(" ");
-			text += attr.getNodeName().rawBuffer();
-			text += _T("=\"");
-			text += attr.getNodeValue().rawBuffer();
-			text += _T("\"");
-		}
+	xmlstream& operator<<(const XMLCh other) {
+		append(&other,1);
+		return *this;
+	}
+
+	BSTR SysAllocString() {
+		if(m_length > 0)
+			return SysAllocStringLen(m_buffer,m_length);
+		return 0;
 	}
 
-	DOM_NodeList childs = node.getChildNodes();
-	length = childs.getLength();
-	if (length > 0) {
-		text += _T(">");
-		for (int i=0; i < length; ++i) {
-			DOM_Node child = childs.item(i);
-			GetXML(child,text);
+private:
+	void append(const XMLCh* other,unsigned long length) {
+		const XMLCh* source = NULL;
+
+		if(m_length + length > m_alloc) {
+			unsigned long chunk = 4096;
+			if(length > chunk) chunk += length;
+			XMLCh* newbuf = new XMLCh[m_alloc+ chunk];
+			m_alloc += chunk;
+			m_next = newbuf + m_length;
+
+			//
+			//    copy old content into new buffer
+			//
+			XMLCh* dest = newbuf;
+			source = m_buffer;
+			for(unsigned long i = 0; i < m_length; i++,dest++,source++) {
+				*dest = *source;
+			}
+			delete [] m_buffer;
+			m_buffer = newbuf;
+		}
+
+		source = other;
+		for(unsigned long i = 0; i < length; i++,source++,m_next++) {
+			*m_next = *source;
 		}
-		text += _T("</");
-		text += tagName;
-		text += _T(">");
+		m_length += length;
 	}
-	else
-		text += _T("/>");
+
+	unsigned long m_length;
+	unsigned long m_alloc;
+	XMLCh* m_buffer;
+	XMLCh* m_next;
+};
+
+
+
+
+// ---------------------------------------------------------------------------
+//  outputContent
+//
+//  Write document content from a DOMString to a C++ ostream. Escape the
+//  XML special characters (<, &, etc.) unless this is suppressed by the
+//  command line option.
+// ---------------------------------------------------------------------------
+void outputContent(xmlstream& target, const DOMString &toWrite)
+{
+    
+        int            length = toWrite.length();
+        const XMLCh*   chars  = toWrite.rawBuffer();
+        
+        int index;
+        for (index = 0; index < length; index++)
+        {
+            switch (chars[index])
+            {
+            case chAmpersand :
+                target << XMLStrL("&amp;");
+                break;
+                
+            case chOpenAngle :
+                target << XMLStrL("&lt;");
+                break;
+                
+            case chCloseAngle:
+                target << XMLStrL("&gt;");
+                break;
+                
+            case chDoubleQuote :
+                target << XMLStrL("&quot;");
+                break;
+                
+            default:
+                // If it is none of the special characters, print it as such
+                target << toWrite.substringData(index, 1);
+                break;
+            }
+        }
+
+    return;
+}
+
+xmlstream& operator<<(xmlstream& target, const DOM_Node& toWrite)
+{
+    // Get the name and value out for convenience
+    DOMString   nodeName = toWrite.getNodeName();
+    DOMString   nodeValue = toWrite.getNodeValue();
+
+
+	switch (toWrite.getNodeType())
+    {
+		case DOM_Node::TEXT_NODE:
+        {
+            outputContent(target, nodeValue);
+            break;
+        }
+
+        case DOM_Node::PROCESSING_INSTRUCTION_NODE :
+        {
+            target  << XMLStrL("<?")
+                    << nodeName
+                    << XMLStrL(' ')
+                    << nodeValue
+                    << XMLStrL("?>");
+            break;
+        }
+
+        case DOM_Node::DOCUMENT_NODE :
+        {
+            //
+            //  Bug here:  we need to find a way to get the encoding name
+            //  for the default code page on the system where the program
+            //  is running, and plug that in for the encoding name.  
+            //
+            //target << "<?xml version='1.0' encoding='ISO-8859-1' ?>\n";
+            DOM_Node child = toWrite.getFirstChild();
+            while( child != 0)
+            {
+                target << child;
+                child = child.getNextSibling();
+            }
+            break;
+        }
+
+        case DOM_Node::ELEMENT_NODE :
+        {
+            // Output the element start tag.
+            target << XMLStrL('<') << nodeName;
+
+            // Output any attributes on this element
+            DOM_NamedNodeMap attributes = toWrite.getAttributes();
+            int attrCount = attributes.getLength();
+            for (int i = 0; i < attrCount; i++)
+            {
+                DOM_Node  attribute = attributes.item(i);
+
+                target  << XMLStrL(' ') << attribute.getNodeName()
+                        << XMLStrL(" = \"");
+                        //  Note that "<" must be escaped in attribute values.
+                        outputContent(target, attribute.getNodeValue());
+                        target << XMLStrL('"');
+            }
+
+            //
+            //  Test for the presence of children, which includes both
+            //  text content and nested elements.
+            //
+            DOM_Node child = toWrite.getFirstChild();
+            if (child != 0)
+            {
+                // There are children. Close start-tag, and output children.
+                target << XMLStrL(">");
+                while( child != 0)
+                {
+                    target << child;
+                    child = child.getNextSibling();
+                }
+
+                // Done with children.  Output the end tag.
+                target << XMLStrL("</") << nodeName << XMLStrL(">");
+            }
+            else
+            {
+                //
+                //  There were no children. Output the short form close of
+                //  the element start tag, making it an empty-element tag.
+                //
+                target << XMLStrL("/>");
+            }
+            break;
+        }
+
+        case DOM_Node::ENTITY_REFERENCE_NODE:
+        {
+            DOM_Node child;
+            for (child = toWrite.getFirstChild(); child != 0; child = child.getNextSibling())
+                target << child;
+            break;
+        }
+
+        case DOM_Node::CDATA_SECTION_NODE:
+        {
+            target << XMLStrL("<![CDATA[") << nodeValue << XMLStrL("]]>");
+            break;
+        }
+
+        case DOM_Node::COMMENT_NODE:
+        {
+            target << XMLStrL("<!--") << nodeValue << XMLStrL("-->");
+            break;
+        }
+
+        case DOM_Node::DOCUMENT_TYPE_NODE:
+        {
+			DOM_DocumentType doctype = (DOM_DocumentType &)toWrite;;
+
+			target << XMLStrL("<!DOCTYPE ") << nodeName ;
+			DOMString id = doctype.getPublicId();
+			if (id != 0)
+				target << XMLStrL(" PUBLIC \"") << id << XMLStrL("\"");
+			id = doctype.getSystemId();
+			if (id != 0)
+				target << XMLStrL(" SYSTEM \"") << id << XMLStrL("\"");
+			id = doctype.getInternalSubset(); 
+			if (id !=0)
+				target << XMLStrL(" [ ") << id  << XMLStrL("]");
+			target  << XMLStrL(">");
+            break;
+        }
+		case DOM_Node::ENTITY_NODE:
+        {
+			target << XMLStrL("<!ENTITY ") << nodeName;
+			DOMString id = ((DOM_Entity &)toWrite).getPublicId();
+			if (id != 0)
+				target << XMLStrL("PUBLIC \"") << id << XMLStrL("\"");
+			id = ((DOM_Entity &)toWrite).getSystemId();
+			if (id != 0)
+				target << XMLStrL("SYSTEM \"") << id << XMLStrL("\"");
+			id = ((DOM_Entity &)toWrite).getNotationName();
+			if (id != 0)
+				target << XMLStrL("NDATA \"") << id << XMLStrL("\"");
+
+            break;
+        }
+        case DOM_Node::XML_DECL_NODE:
+        {
+            target << XMLStrL("<?xml version=") << ((DOM_XMLDecl &)toWrite).getVersion();
+            DOMString str = ((DOM_XMLDecl &)toWrite).getEncoding();
+            if (str != 0)
+                target << XMLStrL(" encoding=") << str;
+            str = ((DOM_XMLDecl &)toWrite).getStandalone();
+            if (str != 0)
+                target << XMLStrL(" standalone=") << str;
+            target << XMLStrL("?>");
+            break;
+        }
+        default:
+            target << XMLStrL("<!-- Unrecognized node type -->");
+    }
+	return target;
 }
+
+void GetXML(const DOM_Node &node, _bstr_t &text)
+{
+	xmlstream stream;
+	stream << node;
+	text.Assign(stream.SysAllocString());
+}
+
diff --git a/src/com/XMLDOMUtil.h b/src/com/XMLDOMUtil.h
index 4ac372949..7a4385257 100644
--- a/src/com/XMLDOMUtil.h
+++ b/src/com/XMLDOMUtil.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:03  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:09  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -73,4 +76,6 @@ void GetXML (const DOM_Node &node, _bstr_t &text);
 void GetText(const DOM_Node& node, _bstr_t &text);
 HRESULT wrapNode(IXMLDOMDocument *pDoc, DOM_Node& node, REFIID iid, LPVOID *pVal);
 
+
+
 #endif // ___wrapnode_h___
\ No newline at end of file
diff --git a/src/com/XMLHTTPRequest.cpp b/src/com/XMLHTTPRequest.cpp
index 7963dde3d..dbb2424bb 100644
--- a/src/com/XMLHTTPRequest.cpp
+++ b/src/com/XMLHTTPRequest.cpp
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:03  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:09  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -174,15 +177,8 @@ LRESULT CXMLHttpRequest::OnReadyStateChange(UINT uMsg, WPARAM wParam, LPARAM lPa
 
 STDMETHODIMP CXMLHttpRequest::InterfaceSupportsErrorInfo(REFIID riid)
 {
-	static const IID* arr[] = 
-	{
-		&IID_IXMLHttpRequest
-	};
-	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
-	{
-		if (InlineIsEqualGUID(*arr[i],riid))
-			return S_OK;
-	}
+	if (IsEqualGUID(IID_IXMLHttpRequest,riid))
+		return S_OK;
 	return S_FALSE;
 }
 
diff --git a/src/com/XMLHttpRequest.h b/src/com/XMLHttpRequest.h
index f411540b9..ba1842b32 100644
--- a/src/com/XMLHttpRequest.h
+++ b/src/com/XMLHttpRequest.h
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:04  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:09  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -71,9 +74,9 @@
 
 class ATL_NO_VTABLE CXMLHttpRequest : 
 	public CComObjectRootEx<CComSingleThreadModel>,
-	public CComCoClass<CXMLHttpRequest, &CLSID_XMLHttpRequest>,
+	public CComCoClass<CXMLHttpRequest, &CLSID_XMLHTTPRequest>,
 	public IObjectSafetyImpl<CXMLHttpRequest, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
-	public IDispatchImpl<IXMLHttpRequest, &IID_IXMLHttpRequest, &LIBID_IBMXMLLib>,
+	public IDispatchImpl<IXMLHttpRequest, &IID_IXMLHttpRequest, &LIBID_Xerces>,
 	public IObjectWithSiteImpl<CXMLHttpRequest>,
 	public ISupportErrorInfo,
 	public CWindowImpl<CXMLHttpRequest, CWindow, CWinTraits<0,0> >
diff --git a/src/com/xml4com.cpp b/src/com/xml4com.cpp
index b54e9e957..8f7346e68 100644
--- a/src/com/xml4com.cpp
+++ b/src/com/xml4com.cpp
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2000/06/03 00:29:04  andyh
+ * COM Wrapper changes from Curt Arnold
+ *
  * Revision 1.2  2000/03/30 02:00:12  abagchi
  * Initial checkin of working code with Copyright Notice
  *
@@ -86,9 +89,26 @@
 #include "stdafx.h"
 #include "resource.h"
 #include <initguid.h>
-#include "xml4com.h"
 
 #include <util/PlatformUtils.hpp>
+#include "xml4com.h"
+
+//
+//   This file is generated from the type library compilation
+//       of xmldom.idl
+//
+//   The define prevent the Microsoft versions of DOMDocument
+//      and HTTPRequest from causing symbol clashes with ours
+#define CLSID_DOMDocument CLSID_MSDOMDocument
+#define CLSID_XMLHTTPRequest CLSID_MSXMLHTTPRequest
+#include "msxml_i.c"
+#undef CLSID_DOMDocument
+#undef CLSID_XMLHTTPRequest
+
+//
+//   This file is generated from the type library compilation
+//       of xml4com.idl
+//
 #include "xml4com_i.c"
 #include "XMLDOMDocument.h"
 #include "XMLHTTPRequest.h"
@@ -100,8 +120,8 @@ extern "C" HINSTANCE hProxyDll;
 CComModule _Module;
 
 BEGIN_OBJECT_MAP(ObjectMap)
-OBJECT_ENTRY(CLSID_XMLDOMDocument, CXMLDOMDocument)
-OBJECT_ENTRY(CLSID_XMLHttpRequest, CXMLHttpRequest)
+OBJECT_ENTRY(CLSID_DOMDocument, CXMLDOMDocument)
+OBJECT_ENTRY(CLSID_XMLHTTPRequest, CXMLHttpRequest)
 END_OBJECT_MAP()
 
 /////////////////////////////////////////////////////////////////////////////
@@ -117,7 +137,7 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
 #endif
     if (dwReason == DLL_PROCESS_ATTACH)
     {
-        _Module.Init(ObjectMap, hInstance, &LIBID_IBMXMLLib);
+        _Module.Init(ObjectMap, hInstance, &LIBID_Xerces);
         DisableThreadLibraryCalls(hInstance);
 		XMLPlatformUtils::Initialize();
     }
diff --git a/src/com/xml4com.idl b/src/com/xml4com.idl
index 7a236e029..b007cea88 100644
--- a/src/com/xml4com.idl
+++ b/src/com/xml4com.idl
@@ -1,3 +1,61 @@
+/*
+ * The Apache Software License, Version 1.1
+ * 
+ * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
+ * reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ * 
+ * 4. The names "Xerces" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache\@apache.org.
+ * 
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ * 
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ * 
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation, and was
+ * originally based on software copyright (c) 1999, International
+ * Business Machines, Inc., http://www.ibm.com .  For more information
+ * on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+
+
 // xml4com.idl : IDL source 
 //
  
@@ -9,13 +67,14 @@ import "oaidl.idl";
 [
 	uuid(79516F60-3AEA-11D3-BC47-0004ACB7DBEB),
 	version(1.0),
-	helpstring("xml4com 1.0 Type Library")
+	helpstring("Xerces XML Parser")
 ]
-library IBMXMLLib
+library Xerces
 {
 	importlib("stdole32.tlb");
 	importlib("stdole2.tlb");
 
+
 	import "xmldom.idl";
 	
 	[
@@ -33,9 +92,9 @@ library IBMXMLLib
 
 	[
 		uuid(79516F6F-3AEA-11D3-BC47-0004ACB7DBEB),
-		helpstring("XMLDOMDocument Class")
+		helpstring("DOMDocument Class")
 	]
-	coclass XMLDOMDocument
+	coclass DOMDocument
 	{
 		[default] interface IXMLDOMDocument;
 		[default, source] dispinterface XMLDOMDocumentEvents;
@@ -43,9 +102,9 @@ library IBMXMLLib
 
 	[
 	  uuid(1C598E82-9AB9-456b-9C24-D711F08F3584),
-	  helpstring("XMLHttpRequest class.")
+	  helpstring("XMLHTTPRequest class.")
 	]
-	coclass XMLHttpRequest
+	coclass XMLHTTPRequest
 	{
 		[default] interface IXMLHttpRequest;
 	};
diff --git a/src/com/xml4com.rc b/src/com/xml4com.rc
index 1c3cf0fb9..7c33a897a 100644
--- a/src/com/xml4com.rc
+++ b/src/com/xml4com.rc
@@ -1,3 +1,60 @@
+/*
+ * The Apache Software License, Version 1.1
+ * 
+ * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
+ * reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ * 
+ * 4. The names "Xerces" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache\@apache.org.
+ * 
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ * 
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ * 
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation, and was
+ * originally based on software copyright (c) 1999, International
+ * Business Machines, Inc., http://www.ibm.com .  For more information
+ * on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+
 //Microsoft Developer Studio generated resource script.
 //
 #include "resource.h"
@@ -71,17 +128,17 @@ BEGIN
         BLOCK "040904b0"
         BEGIN
             VALUE "Comments", "\0"
-            VALUE "CompanyName", "\0"
-            VALUE "FileDescription", "IBM XML Parser\0"
-            VALUE "FileVersion", "1, 0, 0, 1\0"
-            VALUE "InternalName", "IBM XML Parser \0"
-            VALUE "LegalCopyright", "Copyright 1999\0"
+            VALUE "CompanyName", "Apache Software Foundation\0"
+            VALUE "FileDescription", "Xerces XML Parser for COM\0"
+            VALUE "FileVersion", "1, 2, 0\0"
+            VALUE "InternalName", "Xerces XML Parser for COM \0"
+            VALUE "LegalCopyright", "Copyright © Apache Software Foundation 2000 subject to licensing terms\0"
             VALUE "LegalTrademarks", "\0"
             VALUE "OLESelfRegister", "\0"
-            VALUE "OriginalFilename", "IXXML4C3_0.DLL\0"
+            VALUE "OriginalFilename", "xerces-com.dll\0"
             VALUE "PrivateBuild", "\0"
-            VALUE "ProductName", "IBM XML Parser \0"
-            VALUE "ProductVersion", "1, 0, 0, 1\0"
+            VALUE "ProductName", "Xerces XML Parser for COM\0"
+            VALUE "ProductVersion", "1, 2, 0\0"
             VALUE "SpecialBuild", "\0"
         END
     END
-- 
GitLab