blob: e876f16efc49d380245c6fbbeccb7120ceae1cfb [file] [log] [blame]
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001/*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * INTEL CONFIDENTIAL
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02003 * Copyright © 2011 Intel
Patrick Benavoli68a91282011-08-31 11:23:23 +02004 * Corporation All Rights Reserved.
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02005 *
Patrick Benavoli68a91282011-08-31 11:23:23 +02006 * 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.
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020015 *
Patrick Benavoli68a91282011-08-31 11:23:23 +020016 * 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 * CREATED: 2012-08-10
Patrick Benavoli68a91282011-08-31 11:23:23 +020023 */
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020024#include "XmlDocSource.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020025#include <libxml/tree.h>
26#include <stdlib.h>
27
28// Schedule for libxml2 library
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020029bool CXmlDocSource::_bLibXml2CleanupScheduled;
Patrick Benavoli68a91282011-08-31 11:23:23 +020030
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020031CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc, _xmlNode *pRootNode):
32 _pDoc(pDoc), _pRootNode(pRootNode)
Patrick Benavoli68a91282011-08-31 11:23:23 +020033{
Patrick Benavoli592ae562011-09-05 16:53:58 +020034 if (!_bLibXml2CleanupScheduled) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020035
36 // Schedule cleanup
37 atexit(xmlCleanupParser);
38
39 _bLibXml2CleanupScheduled = true;
40 }
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020041
42 if (!_pRootNode) {
43
44 _pRootNode = xmlDocGetRootElement(_pDoc);
45 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020046}
47
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020048CXmlDocSource::~CXmlDocSource()
Patrick Benavoli68a91282011-08-31 11:23:23 +020049{
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020050 if (_pDoc) {
51 // Free XML doc
52 xmlFreeDoc(_pDoc);
53 _pDoc = NULL;
54 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020055}
56
57// Root element
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020058void CXmlDocSource::getRootElement(CXmlElement& xmlRootElement) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020059{
60 xmlRootElement.setXmlElement(_pRootNode);
61}
62
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020063string CXmlDocSource::getRootElementName() const
Patrick Benavoli68a91282011-08-31 11:23:23 +020064{
65 return (const char*)_pRootNode->name;
66}
67
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020068string CXmlDocSource::getRootElementAttributeString(const string& strAttributeName) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020069{
70 CXmlElement topMostElement(_pRootNode);
71
72 return topMostElement.getAttributeString(strAttributeName);
73}
74
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020075_xmlDoc* CXmlDocSource::getDoc() const
76{
77 return _pDoc;
78}
Patrick Benavoli68a91282011-08-31 11:23:23 +020079