]> git.donarmstrong.com Git - flightcrew.git/blob - src/XercesExtensions/XmlUtils.h
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / XercesExtensions / XmlUtils.h
1 /************************************************************************\r
2 **\r
3 **  Copyright (C) 2010  Strahinja Markovic\r
4 **\r
5 **  This file is part of FlightCrew.\r
6 **\r
7 **  FlightCrew is free software: you can redistribute it and/or modify\r
8 **  it under the terms of the GNU Lesser General Public License as published\r
9 **  by the Free Software Foundation, either version 3 of the License, or\r
10 **  (at your option) any later version.\r
11 **\r
12 **  FlightCrew is distributed in the hope that it will be useful,\r
13 **  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 **  GNU Lesser General Public License for more details.\r
16 **\r
17 **  You should have received a copy of the GNU Lesser General Public License\r
18 **  along with FlightCrew.  If not, see <http://www.gnu.org/licenses/>.\r
19 **\r
20 *************************************************************************/\r
21 \r
22 #pragma once\r
23 #ifndef XMLUTILS_H\r
24 #define XMLUTILS_H\r
25 \r
26 #include <vector>\r
27 #include <string>\r
28 #include <xercesc/dom/DOMNode.hpp>\r
29 #include "NodeLocationInfo.h"\r
30 #include "QName.h"\r
31 \r
32 namespace XERCES_CPP_NAMESPACE \r
33 { class DOMElement; class DOMDocument; class DOMAttr; class DOMNodeList; }\r
34 namespace xc = XERCES_CPP_NAMESPACE;\r
35 \r
36 namespace XercesExt\r
37 {\r
38     NodeLocationInfo GetNodeLocationInfo( const xc::DOMNode &node );\r
39 \r
40     NodeLocationInfo GetNearestNodeLocationInfo( const xc::DOMNode &node );\r
41 \r
42     /**\r
43      * Returns a list of elements that are descendants of the provided element\r
44      * that also match the provided qualified name.\r
45      *\r
46      * @param start_element The ancestor element.\r
47      * @param element_qname The qname to search for.\r
48      * @return The matching list of descendants.\r
49      */\r
50     std::vector< xc::DOMElement* > GetElementsByQName( const xc::DOMElement &start_element, \r
51                                                        const QName &element_qname );\r
52 \r
53     /**\r
54      * Returns a list of elements that are present in the provided document\r
55      * that also match the provided qualified name.\r
56      *\r
57      * @param start_element The parent DOM document.\r
58      * @param element_qname The qname to search for.\r
59      * @return The matching list of descendants.\r
60      */\r
61     std::vector< xc::DOMElement* > GetElementsByQName( const xc::DOMDocument &document, \r
62                                                        const QName &element_qname );\r
63 \r
64     std::vector< xc::DOMElement* > GetElementChildren( const xc::DOMElement &element );\r
65 \r
66     std::vector< xc::DOMAttr* > GetAllAttributesFromElements( const QName &element_qname,\r
67                                                               const QName &attribute_qname,\r
68                                                               const xc::DOMDocument &document );\r
69 \r
70     std::vector< xc::DOMElement* > ExtractElementsFromNodeList( const xc::DOMNodeList &node_list );\r
71 \r
72     bool ElementListContains( std::vector< xc::DOMElement* > element_list,\r
73                               const QName &element_qname );\r
74 \r
75    /**\r
76      * From the provided list of element names, returns the first element\r
77      * present in the document.\r
78      *\r
79      * @param element_qnames The list of element names to search for.\r
80      * @param document The parent DOM document.\r
81      * @return The first element matching one of the provided names\r
82      *         or NULL if none were found.\r
83      */\r
84     xc::DOMNode* GetFirstAvailableElement( const std::vector< QName > &element_qnames,\r
85                                            const xc::DOMDocument &document );\r
86 \r
87    /**\r
88      * Returns the first element present in the document that matches\r
89      * the provided name.\r
90      *\r
91      * @param element The element to search for.\r
92      * @param document The parent DOM document.\r
93      * @return The first element matching the provided name\r
94      *         or NULL if none were found.\r
95      */\r
96     xc::DOMNode* GetFirstAvailableElement( const QName &element_qname,\r
97                                            const xc::DOMDocument &document );\r
98     \r
99     void XercesStringDeallocator( XMLCh *xstring );\r
100 \r
101     template< class T >\r
102     void XercesDeallocator( T *xerclass )\r
103     {\r
104         xerclass->release();\r
105     }\r
106 }\r
107 \r
108 #endif // XMLUTILS_H\r