GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: XIncludeDOMDocumentProcessor.cpp 655706 2008-05-13 01:08:39Z amassari $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp> 00027 #include <xercesc/xinclude/XIncludeUtils.hpp> 00028 #include <xercesc/dom/DOM.hpp> 00029 #include <xercesc/util/XMLUniDefs.hpp> 00030 #include <xercesc/framework/XMLErrorReporter.hpp> 00031 00032 XERCES_CPP_NAMESPACE_BEGIN 00033 00034 DOMDocument * 00035 XIncludeDOMDocumentProcessor::doXIncludeDOMProcess(const DOMDocument * const source, XMLErrorReporter *errorHandler, XMLEntityHandler* entityResolver /*=NULL*/){ 00036 XIncludeUtils xiu(errorHandler); 00037 00038 DOMImplementation* impl = source->getImplementation(); 00039 DOMDocument *xincludedDocument = impl->createDocument(); 00040 00041 try 00042 { 00043 /* set up the declaration etc of the output document to match the source */ 00044 xincludedDocument->setDocumentURI( source->getDocumentURI()); 00045 xincludedDocument->setXmlStandalone( source->getXmlStandalone()); 00046 xincludedDocument->setXmlVersion( source->getXmlVersion()); 00047 00048 /* copy entire source document into the xincluded document. Xincluded document can 00049 then be modified in place */ 00050 DOMNode *child = source->getFirstChild(); 00051 for (; child != NULL; child = child->getNextSibling()){ 00052 if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){ 00053 /* I am simply ignoring these at the moment */ 00054 continue; 00055 } 00056 DOMNode *newNode = xincludedDocument->importNode(child, true); 00057 xincludedDocument->appendChild(newNode); 00058 } 00059 00060 DOMNode *docNode = xincludedDocument->getDocumentElement(); 00061 /* parse and include the document node */ 00062 xiu.parseDOMNodeDoingXInclude(docNode, xincludedDocument, entityResolver); 00063 00064 xincludedDocument->normalizeDocument(); 00065 } 00066 catch(const XMLErrs::Codes) 00067 { 00068 xincludedDocument->release(); 00069 return NULL; 00070 } 00071 catch(...) 00072 { 00073 xincludedDocument->release(); 00074 throw; 00075 } 00076 00077 return xincludedDocument; 00078 } 00079 00080 XERCES_CPP_NAMESPACE_END