source: icXML/icXML-devel/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 3.0 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: XIncludeDOMDocumentProcessor.cpp 655706 2008-05-13 01:08:39Z amassari $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp>
27#include <xercesc/xinclude/XIncludeUtils.hpp>
28#include <xercesc/dom/DOM.hpp>
29#include <xercesc/util/XMLUniDefs.hpp>
30#include <xercesc/framework/XMLErrorReporter.hpp>
31
32XERCES_CPP_NAMESPACE_BEGIN
33
34DOMDocument *
35XIncludeDOMDocumentProcessor::doXIncludeDOMProcess(const DOMDocument * const source, XMLErrorReporter *errorHandler, XMLEntityHandler* entityResolver /*=NULL*/){
36    XIncludeUtils xiu(errorHandler);
37
38    DOMImplementation* impl = source->getImplementation();
39    DOMDocument *xincludedDocument = impl->createDocument();
40   
41    try
42    {
43        /* set up the declaration etc of the output document to match the source */
44        xincludedDocument->setDocumentURI( source->getDocumentURI());
45        xincludedDocument->setXmlStandalone( source->getXmlStandalone());
46        xincludedDocument->setXmlVersion( source->getXmlVersion());
47
48        /* copy entire source document into the xincluded document. Xincluded document can
49           then be modified in place */
50        DOMNode *child = source->getFirstChild();
51        for (; child != NULL; child = child->getNextSibling()){
52            if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){
53                /* I am simply ignoring these at the moment */
54                continue;
55            }
56            DOMNode *newNode = xincludedDocument->importNode(child, true);
57            xincludedDocument->appendChild(newNode);
58        }
59
60        DOMNode *docNode = xincludedDocument->getDocumentElement();
61        /* parse and include the document node */
62        xiu.parseDOMNodeDoingXInclude(docNode, xincludedDocument, entityResolver);
63
64        xincludedDocument->normalizeDocument();
65    }
66    catch(const XMLErrs::Codes)
67    {
68        xincludedDocument->release();
69        return NULL;
70    }
71    catch(...)
72    {
73        xincludedDocument->release();
74        throw;
75    }
76
77    return xincludedDocument;
78}
79
80XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.