blob: c323e440caebf631352b38f92ba49593e3879474 [file] [log] [blame]
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001/*
2 * INTEL CONFIDENTIAL
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02003 * Copyright © 2013 Intel
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02004 * 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.
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020021 */
22
23#include "XmlMemoryDocSource.h"
24#include <libxml/parser.h>
25#include <libxml/tree.h>
26
27#define base CXmlDocSource
28
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020029CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource,
30 const string& strRootElementType,
31 const string& strXmlSchemaFile,
32 const string& strProduct,
33 const string& strVersion):
34 base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())),
35 _pXmlSource(pXmlSource), _strXmlSchemaFile(strXmlSchemaFile), _bWithHeader(true),
36 _strProduct(strProduct), _strVersion(strVersion)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020037{
38 init();
39}
40
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020041CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource,
42 const string& strRootElementType):
43 base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())),
44 _pXmlSource(pXmlSource), _bWithHeader(false)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020045{
46 init();
47}
48
49void CXmlMemoryDocSource::init()
50{
51#ifdef LIBXML_TREE_ENABLED
52
53 // Assign it to document
54 xmlDocSetRootElement(_pDoc, _pRootNode);
55#endif
56}
57
58bool CXmlMemoryDocSource::populate(CXmlSerializingContext& serializingContext)
59{
60#ifndef LIBXML_TREE_ENABLED
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020061 serializingContext.setError("XML file exporting feature unsupported on this image. " +
62 "This easiest way to activate it is to do a global " +
63 "recompilation with LIBXML_TREE_ENABLED compiler switch set");
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020064
65 return false;
66#endif
67
68 // Create Xml element with the Doc
69 CXmlElement docElement(_pRootNode);
70
71 if (_bWithHeader) {
72
73 // Schema namespace
74 docElement.setAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
75
76 // Schema location
77 docElement.setAttributeString("xsi:noNamespaceSchemaLocation", _strXmlSchemaFile);
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020078 }
79
80 // Compose the xml document
81 _pXmlSource->toXml(docElement, serializingContext);
82
83 return true;
84}