blob: 4df2ad1b5eab951b2145a5860fc5a9b91dcef0ce [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 "XmlFileDocSource.h"
26#include <libxml/parser.h>
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020027
28#define base CXmlDocSource
29
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020030CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile,
31 const string& strXmlSchemaFile,
32 const string& strRootElementType,
33 const string& strRootElementName,
34 const string& strNameAttrituteName) :
35 base(xmlReadFile(strXmlInstanceFile.c_str(),NULL, 0),
36 strXmlSchemaFile,
37 strRootElementType,
38 strRootElementName,
39 strNameAttrituteName),
40 _strXmlInstanceFile(strXmlInstanceFile)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020041{
42}
43
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020044CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile,
45 const string& strXmlSchemaFile,
46 const string& strRootElementType) :
47 base(xmlReadFile(strXmlInstanceFile.c_str(), NULL, 0),
48 strXmlSchemaFile,
49 strRootElementType),
50 _strXmlInstanceFile(strXmlInstanceFile)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020051{
52}
53
Frédéric Boisnarda409daa2012-10-18 18:20:03 +020054bool CXmlFileDocSource::isParsable(CXmlSerializingContext& serializingContext) const
55{
56 // Check that the doc has been created
57 if (!_pDoc) {
58
59 serializingContext.setError("Could not parse file " + _strXmlInstanceFile);
60
61 return false;
62 }
63
64 return true;
65}
66
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020067bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020068{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020069 if (!base::validate(serializingContext)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020070
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020071 // Add the file's name in the error message
72 serializingContext.appendLineToError("File : " + _strXmlInstanceFile);
73
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020074 return false;
75 }
76
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020077 return true;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020078}