blob: ffa86e392b8e3c131c2753d141a388511a25d6c6 [file] [log] [blame]
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001/*
2 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
22 * CREATED: 2012-08-10
23 */
24
25#include "XmlMemoryDocSource.h"
26#include <libxml/parser.h>
27#include <libxml/tree.h>
28
29#define base CXmlDocSource
30
31CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType, const string& strXmlSchemaFile, const string& strProduct, const string& strVersion):
32 base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())), _pXmlSource(pXmlSource), _strXmlSchemaFile(strXmlSchemaFile), _bWithHeader(true), _strProduct(strProduct), _strVersion(strVersion)
33{
34 init();
35}
36
37CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType):
38 base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())), _pXmlSource(pXmlSource), _bWithHeader(false)
39{
40 init();
41}
42
43void CXmlMemoryDocSource::init()
44{
45#ifdef LIBXML_TREE_ENABLED
46
47 // Assign it to document
48 xmlDocSetRootElement(_pDoc, _pRootNode);
49#endif
50}
51
52bool CXmlMemoryDocSource::populate(CXmlSerializingContext& serializingContext)
53{
54#ifndef LIBXML_TREE_ENABLED
55 serializingContext.setError("XML file exporting feature unsupported on this image. This easiest way to activate it is to do a global recompilation with LIBXML_TREE_ENABLED compiler switch set");
56
57 return false;
58#endif
59
60 // Create Xml element with the Doc
61 CXmlElement docElement(_pRootNode);
62
63 if (_bWithHeader) {
64
65 // Schema namespace
66 docElement.setAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
67
68 // Schema location
69 docElement.setAttributeString("xsi:noNamespaceSchemaLocation", _strXmlSchemaFile);
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020070 }
71
72 // Compose the xml document
73 _pXmlSource->toXml(docElement, serializingContext);
74
75 return true;
76}